Homework 3
Released | Due |
---|---|
TBD | TBD |
Homework 3
Part 1: Scrutinizing Strings
Task 1: Write a function valid-name that takes a single String of a first and last name separated by a space, and a String for the desired initials (example: BR for Bob Ross). The function returns true if the name is valid and false if the name is invalid. A name will be valid if the first and last name match the desired initials, there is a single space between them and the name does not contain the character “!”.
Take a look at the string documentation for some helpful functions.
Task 2: Write out a few tests to make sure the function works as intended. In a comment briefly explains what kind of names that we see in the real world this function would not account for.
Here are two examples to get you started:
check:
valid-name("Bob Ross", "BR") is true
valid-name("RossBob", "RB") is false
end
Part 2: Checks and Tests
Imagine you taught a computer science class at an amazing university called DMU and assigned a project to a large group of students. You asked them to make a function check-date which returns true if a given string is a valid date and false if it is not. In this case a valid date has the format MM/YYYY where MM is the month and YYYY is the year (all M’s and Y’s are numerical digits). Since you want to be able to grade all the projects fairly and quickly, you decide to create a check block to test that the student’s code produces the correct results.
For example:
check:
check-date("11/2023") is true
end
Task 3: Create a check block with tests to determine if a provided implementation of check-date is working as intended. Pyret will run your tests against several versions of check-data that we have written and display the number of faulty implementations you have eliminated.
You are not writing the check-date function yourself, only tests for it!
Task 4: In a comment summarize your strategy and how it may be applicable to writing future tests.
Part 3: Setting the Table
A streaming company Metrix has tasked you with creating a function to provide movie recommendations from their table of movies based on user’s profiles and preferences. Write a function movie-recommend that takes a row of the table, the user’s favorite movie stars and company along with the user’s age, and outputs true if the user is likely to enjoy this movie and false otherwise. Metrix’s research has shown that the following criteria will indicate that someone will enjoy a movie:
- The movie came out after the user was 5 years old
- The movie has one of their favorite movie stars
- If the user is under the age of 15 do not recommend horror movies
- The score needs to be at least 5.0 if the movie is made by the user’s favorite studio, but must be at least 6.5 if made by someone else
Here is a part of the table that we will be using:
sample-movies = table: name :: String, rating :: String, genre :: String, released :: Number, score :: Number, director :: String, writer :: String, star :: String, company :: String, runtime :: Number
row: "The Shining", "R", "Drama", 1980, 8.4, "Stanley Kubrick", "Stephen King", "Jack Nicholson", "Warner Bros.", 146
row: "The Blue Lagoon", "R", "Adventure", 1980, 5.8, "Randal Kleiser", "Henry De Vere Stacpoole", "Brooke Shields", "Columbia Pictures", 104
end
Here is an example of a potential input for age, favorite movie stars, and favorite company:
age = 60
favorite-stars = "Nicolas Cage, Liam Neeson, Leslie Cheung, Colin Firth, Scarlett Johansson, Jack Nicholson, Brooke Shields"
favorite-company = “Warner Bros.”
Task 5: Create functions (with a descriptive names!) that checks for each of the conditions given by Metrix.
Task 6: Use the functions you created in Task 5 to make movie-recommend.
Hint: It’s a good idea to test each function individually to make sure they all work as intended, before trying to put everything together.
Task 7: Follow the documentation for how to import this table of movies from Google sheets.
Task 8: Using movie-recommend create a function movie-list that takes in a table (like the one from part 7), age, favorite movie stars and company, and returns all the recommended movies (i.e. rows) sorted order from newest to oldest release.
Task 9: In a film class you are taking, you’re covering poorly rated movies, and the professor asked you to choose a movie for next class. To be appropriate for class, the movie should be rated “PG” or “G” and since class lasts from 2:00 till 3:15, the movie must be under 75 minutes long. Make a function bad-movies that takes a table, and returns those rows which meet the criteria sorted from lowest to highest rating.
Part 4: Metrix vs Netflix
Task 10: Read this article on how netflix’s algorithm determines what to recommend to its users.
Task 11: Answers the flowing questions:
- What sort of company, besides movie / video streaming, may want to use the data Netflix collects?
- Give an example how this company could benefit from having that information.
- What is the best service you have used at giving you recommendations (music streaming, videos, shopping, etc)?
- What specifically did this service do well?
- Look up and briefly describe what information this service collects.
- Is there any user data you think a company should not be allowed to store about its users?
- What information would you want access to in order to design an algorithm for recommending classes to other students?
These questions don’t have a right or wrong answers. The goal here is to consider what data is collected, how it is being used, and what impacts that may have. We are not expecting a multi-page research paper, but give each question some thought and provide a concrete answer.