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

### Problem Set 3

Due date: 10/09

Purpose:

The goal of this problem set is to help you design functions that deal with arbitrarily large data, especially forests of trees and trees of forests, and forests of forests.

#### Drill:

HtDP: 14.1.4, 14.1.6, 14.2.1, 14.2.2, 14.2.3, 14.2.4, 17.6.4, 17.6.6, 17.7.1, 17.7.2, 17.7.3, 17.7.4

#### Required Problems:

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

1. An artist produces mobiles that each consist of either a hanging, heavy sculpture or a balanced beam with multiple mobiles hanging from each end of the beam:

The artist is asking for a program that helps her create these artifacts. In particular, she wishes for a Boolean-typed function that checks whether a mobile is balanced. She considers a mobile balanced if the weights on both sides of the join points are the same and each mobile on both sides is balanced; see above for two balanced mobiles. Assume that she can balance the mobile once this problem is solved.

Design this program.

2. Design the function `sumF`, which adds up all the numbers that occur in a forest. Here are the relevant data definitions:
``````
;; A Forest is one of:
;;  -- empty
;;  -- (cons Tree Forest)
;; A Tree is one of:
;;  -- Number
;;  -- (cons Tree (cons Number (cons Tree empty)))
``````
3. Design a program that renders an "Enum" as an image:
``````
(define-struct ul (list))
;; Enum is one of:
;; -- (make-ul LOI)
;; LOI is one of:
;; -- (cons Item empty)
;; -- (cons Item LOI)
;; Item is one of:
;; -- String
;; -- Enum
``````
The rendering program consumes an `enum` and an image. The former specifies the content and organization of the enumeration; the latter is the chosen enumeration anchor (i.e., bullet or circle) that is used for all items during the rendering process.

Here are two examples:

Hint: This problem is related to problems 1.3 and 2.3. Do try to reuse the images (bullets) and image composition functions you designed for those problems but do start from scratch for the rest. Otherwise you will spent a long time on this problem.

Domain knowledge: The rendering inserts exactly one "string space" between the "enumeration anchor" (i.e., bullet or circle) and the item if it is a text; otherwise the renderer stacks a blank line `(text "" 11 'black)` and the enumeration.

4. Project: Finish problem 2.4.
5. Add a horizontal wall to the middle of the box. This additional wall should not stretch across the entire width of the box. The ball's initial position and velocity may be such that it bounces off of all three surrounding walls as well as off of both sides of the added horizontal wall. Of course, it may also take it outside of the box.

Continue to use a `move` function that for any given tick, moves the ball to the closest obstacle and bounces if (if necessary). In other words, the function does not compute the effect of multiple bounces per tick.

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