CIS 199

Final Exam

Due: Mar 21, 4:25 P.M.

This final exam for this class is a take-home final consisting of two programming projects. There are several pieces to each project, and you can earn partial credit by completing some parts of one or both projects.

Important Notes

Project 1: March Madness

Download games.txt, a text file that has scores from the NCAA Men's Basketball Tournament for the last four years.

Each line contains the result of a single game. There are five items on each line in this file:

The file is in "tab separated values" (TSV) format, which means there is a single tab character ("\t") separating the items on each line. Here are two example lines from the file:

2006   Seton Hall      66      Wichita State   86
2006   Wisconsin-Milwaukee     82      Oklahoma        74

Note that the winning team could be either the first or second team. Note also that team names can have embedded spaces or special characters so don't assume a name consists only of letters.

Your job is to write a program that identifes the team with the best overall winning percentage. For example, if a team won 4 games and lost 2 games, they played 6 games in all and their winning percentage is 4 / 6 = 0.667.

A suggested outline is as follows (but make sure you read the important notes below first before you jump in and starting coding):

Important Notes:

Project 2: iTunes Library

When you load a CD into your iTunes library you get a new directory for the CD, and inside that directory is one file for each song. For example, when I loaded Another Day on Earth by Brian Eno I got:

% ls
01 This.m4a
02 And Then So Clear.m4a
03 A Long Way Down.m4a
...

If you then use iTunes to convert the songs to a new format you get a second copy of the file. On the Mac, the second file has the same name as the first, but with " 1" attached. For example, if I originally load the CD and have it encoded with the ALE format, and then ask iTunes to convert it to MP3, this is what I get:

% ls | cat
01 This 1.m4a
01 This.m4a
02 And Then So Clear 1.m4a
02 And Then So Clear.m4a
03 A Long Way Down 1.m4a
03 A Long Way Down.m4a
...

Since I don't want to have two copies of each song in my iTunes libary, I want to move the copies to a separate library. If I want to use this new directory as my library I can switch (e.g. if I want to load the MPGs onto my iPod). But when I do this I don't want to see " 1" in the name of the song so I should rename all the files as I move them.

Your job is to write a script named movemusic.rb that moves the extra copy of each song to a new directory, renaming the copy as it does the move. To test your program, download itunes.tgz, which is a fake iTunes library. It has file names based on files in a real library, but the files are all empty (as if you really wanted a copy of my files -- I have strange tastes).

The basic program should have two command line arguments, the name of the source directory and the name of the destination directory. For example, when you unpack the tar file, you will have directory named itunes with three subdirectories, one for each of three different CDs. To separate out the MPG files to a new directory named mp3s, type

% movemusic.rb itunes mp3s

For each directory x in the source, look to see if there are any files that end with " 1". If so, make a new directory named x in the destination, and copy all the extra files to the new directory. Rename the files in the new location so they do not have the " 1" at the end.

Some extra things you can add to your program:

If you're really adventurous (and have a Mac), figure out how to invoke Applescript from within your Ruby program. Use Applescript to tell iTunes to reformat a specified CD, and then move all the duplicates.