5. Lists I:  Definitions and Examples: Homework

Last revision:  January 26 1998

Author: YourNameGoesHere

0: Evaluate this first!

First, execute the commands below to define a list named "movieData".

Clear[movieData];
movieData =
{{"Apocalypse Now",  4, 7, 3}, 
 {"The Sting", 8, 8, 7},
 {"The Wizard of Oz", 4, 7, 3},
 {"Bedtime for Bonzo", 2, 10, 5 },
 {"The Last House on the Left", 0, 0, 0},
 {"Gone with the Wind", 8, 8, 8},
 {"Casablanca", 10, 10, 10},
 {"The King of Hearts", 10, 10, 10},
 {"My Fair Lady", 8, 8, 7},
 {"The Sound of Music", 5, 7, 5},
 {"Independence Day", 8, 7, 7},
 {"Mighty Ducks I", 8, 8, 8},
 {"The Rock", 6, 7, 5},
 {"This Island Earth", 3, 4, 6},
 {"Ishtar", 3, 3, 4},
 {"Grumpy Old Men", 8, 9, 8},
 {"The Bridges of Madison County", 9, 9, 8},
 {"Tron", 10, 8, 8},
 {"Blade Runner", 10, 9, 9},
 {"Fearless Hyena", 2, 2, 4},
 {"Space Jam", 3, 6, 7},
 {"Twister", 6, 6, 6},
 {"Phenomenon", 6, 7, 8},
 {"Broken Arrow", 6, 7, 7},
 {"The Killer", 4, 4, 8},
 {"A Better Tomorrow", 8, 8, 8},
 {"Judge Dredd", 7, 5, 6},
 {"Shane", 8, 7, 7},
 {"MST 3K the Movie", 3, 6, 6},
 {"Assassins", 7, 7, 6},
 {"Renaissance Man", 4, 6, 4}
};

(Note: the semicolon at the end of the definition for movieData suppresses the display of its value.)

Each entry in movieData is of the form {"Movie Name", s, a, d} where "s", "a" and "d" are a critic's ratings (on a scale of 0 to 10) for the script, acting, and directing, respectively, of the movie.

1: How many movies?

Write a Mathematica expression which will return the current number of movies represented in movieData.

2: Insert a new movie.

Make up a new entry for movieData and append it to movieData.  (Make sure that an evaluation of movieData later will include your movie.  In particular, evaluation of your expression for the previous question should yield an answer which is 1 more than before.)

3: Alphabetic display.

Display "movieData" in alphabetic order by title.  (Use TableForm[] to produce a display with each move entry on its own line and columns nicely aligned.)

4: Define summaryRating[]

Define a function "summaryRating[]" of a single parameter, a movie entry "m", which returns the average of the script, acting and directing ratings for "m".  Check your function by evaluating "summaryRating[{"Apocalypse Now", 4, 7, 3}]"   
This should produce the answer 4.66667

summaryRating[{"Apocalypse Now", 4, 7, 3}]summaryRating[{Apocalypse Now, 4, 7, 3}]

5: Define includeSummary[]

Define a function "includeSummary[]" of a single parameter, a movie entry "m", which returns the list "m" with its summaryRating inserted in front.  Check your function by evaluating "includeSummary[{"Apocalypse Now", 4, 7, 3}]"   
This should produce the answer {4.66667, "Apocalypse Now", 4, 7, 3}

includeSummary[{"Apocalypse Now", 4, 7, 3}]

6: Include summaries in table of movies.

Use "movieData" to define a new list "summarizedMovieData".  An entry in "summarizedMovieData" is of the form {r, "Movie Name", s, a, d} where "r" is the average of "s", "a" and "d".   (The Map[] funciton should be helpful here.)

7: Display from best-to-worst.

Display "summarizedMovieData" in order by summarized rating, with the movie rating highest appearing first.  (Use TableForm[] to produce a nice display.)

8: More compact display from best-to-worst.

Define a function "first2[]" of a single parameter, a list "ls", which returns the list consisting of the first two entries in "ls".  Check your function by evaluating "first2[{4.66667, "Apocalypse Now", 4, 7, 3}]" .  
This should produce the answer  {4.66667, "Apocalypse Now"}

first2[{4.66667, "Apocalypse Now", 4, 7, 3}]

Display the summary ratings and movie names (but not the script/acting/directing numbers) found in "summarizedMovieData" in order by summarized rating, with the movie rating highest appearing first.