Problem Set 2
Language: Beginning Student
Due: 11:59 PM Sunday Jan. 20
Remember to use the design recipe to craft your functions -- in particular, include a signature, purpose, and tests, and (for this assignment) also include commented templates for each function.
1 Euclidean Distance
These functions are similar. Avoid “copied code” in their definitions.
2 Zoo Animals
Complete Exercise 7.2.1 in HTDP/1e, except for the design of a fits? function. Leave the template commented out in the solution you submit.
Design a function extra-leg-room that determines how much space an animal needs to rest comfortably during transport. Assume that spiders prefer an extra 10% beyond what’s strictly required, elephants prefer an extra 20%, and monkeys prefer an extra 100%. Leave the template commented out in the solution you submit.
- Write the template for the following data definition.
; a zoo is either ; - empty, or ; - (cons animal zoo) Hint: write a helper function that does most of the work. Think about the attribute of the zoo as a whole that's important here, and write a function that returns it.
Design a function zoo-fits-comfortably? that determines whether all animals in a zoo can be comfortably transported in a cargo container of a particular size. Leave the template commented out in the solution you submit.