Homework 6: Much Ado About Lists!

Due: Tuesday October 22, 2019 at 9:00PM EST.


After completing the homework, you will submit:

If you are using late days, make sure to make a note of that in your readme. Remember, you may only use a maximum of 3 late days per assignment. If the assignment is late (and you do NOT have anymore late days) no credit will be given.
After completing the homework, you will submit:

Helpful Things


The Assignment

This assignment draws on some basic ideas about analyzing text. Modern text analysis would use tables and statistics as part of its interpretation. We are doing less of that (since our focus is on list programs this week), but the first few questions are motivated by the text-analysis context.

For some of these problems, we will tell you whether to use the built-in list operations (like L.map and L.filter) or an explicit-recursion function as we have been writing in lecture. Check for italicized notes under each list-processing function for instructions on this.

A literary endeavor

Nicole and Filmore were out investigating a mystery house in Providence when they stumbled upon an old stone tablet. After some research, they found out that the tablet is a map to the lost Providence Treasure! Help Nicole and Filmore crack the tablet’s text and find the treasure! Put your answers to 1-6 in shakespeare.arr.

Converting Text to a List of Words

  1. Nicole notices that the text on the tablet is from the first act of Shakespeare’s Much Ado About Nothing. This text is named book-text in the stencil code. You can see the text in full here. Nicole needs your help to examine individual words in the text to analyze them for clues. Split book-text into a list of words, using the builtin string-split-all (in the Pyret Strings documentation). Name the resulting list of words/strings split-text.

Identifying Characters

  1. Nicole wants to compute the names of all the characters in the play. In the text, only the names of characters are in ALL CAPS. To find which of the words in split-text are characters, we want a function that takes a list of Strings representing a play and returns a list of Strings that contains the names of all characters in the play, without duplicates. The order of characters doesn’t matter.

    NOTE: Write this function two ways, once using only built-in list operators and once with explicit recursion to locate the names (you can still use L.distinct as part of your recursive version). Name your versions find-charactersO (operator version – last char is letter O not zero) and find-charactersR (recursive version).

Tallying Lines Per Character

The ALL-CAPS names mark each character’s spoken lines in the text. Nicole wants to determine how many lines each character has, while also setting up her results for use in a later analysis.

  1. Write a function characters-table which takes in a list of Strings representing the names of characters in a play, and a list of Strings representing the text of the play. This function should return a table with two columns: name and count. The name column should contain every character’s name in the order it was listed in the first argument to your function. The count column should contain the number of times that character’s name occurred in ALL-CAPS.

    To construct the table here, use the following two functions, which are in the cs111-2019 file you included at the top:

    • create-table-with-col(colname :: String, colvals :: List) -> Table
    • add-col :: (t :: Table, name :: String, colvals :: List<Any>) -> Table

    The first one creates a table with one column. The second adds a column to an existing table. For add-col, the number of values in the colvals argument must equal the number of rows in the table (they will be added in order). The following example shows how to build a table of room seating capacity:

    new-table = create-table-with-col("room", [list: "CIT 101", "CIT 368"])
    add-col(new-table, "seats", [list: 10, 65])

    NOTE: you may solve this problem however you like, with recursion, built-in operators, or a mix of the two.

Average word length

  1. Write a function average-word-length which takes in a List of Strings and returns the average length of all words in the list, rounded to the nearest integer (use the builtin num-round).

    NOTE: you may solve this problem however you like, with recursion, built-in operations, or a mix of the two.

Where’s Waldo??

  1. Filmore got a secret clue! “Waldo” is hidden somewhere in the “Much Ado About Nothing” text. But the clue doesn’t contain any hints about where to find Waldo. Write a function find-waldo which takes a single string of text as input and returns the word that occurs immediately after “Waldo” in that text.

    For example, if the String is “the evening breeze Waldo rustled the leaves on the balcony”, then your function should return “rustled”: it should always return the word immediately after Waldo. You may assume that “Waldo” will always be present exactly one time and it will not be the last word of the list.

    NOTE: Solve this problem using recursion rather than built-in operators.

  2. For the last question, we only asked you to find the word directly after waldo, but we might also have asked you to find the words directly before and after him (for our example above, this result would have been [list: "breeze", "rustled"]). What makes that version of the problem more challenging given what we’ve learned so far? What ideas do you have about how you might do that if we asked? You do NOT have to write the code for this version, but if you want to give it a try you are welcome to do so (call it find-waldo-2).

Waldo’s Snacks

Material for this question will be covered later this week

Once Filmore finds Waldo, he reveals that he has been hiding among the rustling leaves for years, waiting for someone to find him, and he is very hungry. Filmore has a bag of mystery food supplies, but he doesn’t know which are good to give Waldo. He decides to build a datatype to help him track his food supplies and decide what to give Waldo.

  1. Create a datatype for a FoodItem. There is one constructor food that takes in a food-name (String), a days-until-expiration (Number) and food-group (String). The food-group will be something like “fruit”, “vegetable”, “grain”, “dairy”, etc.

    Also create a list ofFoodItems called food-list, containing three foods you think Waldo might enjoy (your choice).

  2. Finally, write a function is-expired that takes one FoodItem and returns a boolean indicating whether the days-until-expiration is below zero.


No additional responses required for this week! Still submit a README though (we use it to track late days and collaboration stuff)!

Brown University CSCI 0111 (Fall 2019)
Do you have feedback? Fill out this form.