CSci 1301: Problem Set 4

Due: Monday, November 12th at 11:59pm

Please make sure that every function has a signature, description, and test cases (as needed).

Problem 1

Read Chapter 9 of the book, paying attention to the design recipe for lists (it summarizes and rephrases the same thing we were discussing in class).
Then do the following problems, including the check-expect tests, signatures, descriptions, and then the implementation:

  1. Exercise 140 (5 points).
  2. A function that takes a list of strings and produces the sum of their lengths (5 points).
  3. A function that takes a list of positions and another position (let's call it X) and produces the sum of distances from each of the positions on the list to X (5 points). Hint: write and use a helper distance function (think of what its signature would be).

Problem 2

  1. Exercise 169 (5 points)
  2. Exercise 170 (5 points)
  3. Write a function that takes a list of strings and returns a list of their length (3 points).
  4. Write a function that takes a list of strings and returns a list of all strings on that list that don't start with a lower-case or upper-case "a" (3 points).

Problem 3

Read Section 11.3 in the textbook and do the following exercises:

  1. Exercise 187 (4 points)
  2. Exercise 188 (4 points)
  3. Exercise 190 (write both prefixes and suffixes functions) (9 points). Make sure to start with check-expects and a signature. Note that the function needs a recursive helper function. Don't forget to write signatures before you write the any code!

    Clarification of the problem: There are two possible interpretations of "all prefixes": Both approaches have their challenges, but can be solved by carefully thinking of a solution in terms of the recursive case and the first element.

How to submit

Submit your file(s) via canvas, make sure to name them as required.


CSci 1301 course web site.