107 F '08
The Recipes
The Style
The Universe
The World
Set 1
Set 2
Set 3
Set 4
Set 5
Set 6
Set 7
Set 8
Set 9
Set 10
Set 11

Problem Set 4


Due date: 10/16


The goal of this problem set is to help you design abstractions and to deploy pre-defined abstractions in a functional context. In addition, the assignment should familiarize you with closures.


HtDP: 19.1.5, 20.2.4 (also see 20.2.2), 21.2.1, 21.2.2, 21.2.3

Required Problems:

Note: You must use DrScheme's HtDP Intermediate Student Language with Lambda.

  1. The union of German professors negotiated the following pay scale in 1878: The base salary is 4,000E. For each five years over the age of 30, a professor is paid an age bonus factor of two (2) percent over the base salary; e.g., a 36-year old earns an additional 2% of the base salary. Furthermore, a married professors receives a 500E bonus. For each dependent child, the pay is increased by 225.75E. The contract has been adapted on a yearly basis; e.g., it now specifies Euros instead of Reichsmark.

    The centralized payment office represents a single professor with a five-field personnel record: first name, last name, year of birth, marital status (boolean), and the number of children. A pay check record consists of three pieces: first name, last name, and the monthly gross salary. Design a function that computes the pay check information from a given personnel record. You may assume that the current year is specified as a global constant.

    Design the following functions:

    1. pay-all, which computes the pay check information for a list of personnel records;
    2. pay-sum, which computes the total sum paid out for a list of personnel records; and
    3. pay-order, which creates a list of personnel records ordered in decreasing order according to salary.
    Use existing abstractions where possible.

  2. Use the list abstractions from the table on page 313 in HtDP to simplify the definitions of your solutions of 3.1 and 3.2.

  3. Solve problems 23.4.1, 23.4.2. These problems are about using functions as first-class values.

  4. Project: Abstract over the similarities in your solutions. Promised there are a bunch if you followed the design guideline of one function per task. If not, you better take the time to re-design your program now.

    Extend your solution of problem 3.4 so that the simulation works with a number of balls, not just one.

    Design the function create-world, which consumes a number N and produces a list of N random balls located within the box and moving in random positions. The speed in the Y direction should be between -10 and +10 but not 0; the speed in the X direction should be anywhere in the same interval, including 0. (Optional: Design a function that eliminates duplicate balls from this list. Why is this something that you don't really need?)

    For each tick, move all balls according to the laws of exercise 3.4.

    When a ball leaves the box through the top, eliminate it from the list. When all balls are gone, the simulation is over.

    Constraint: There is no need to consider collisions of balls. Assume they may pass through each other.

last updated on Tue Jun 9 22:21:18 EDT 2009generated with PLT Scheme