Due date: 10/09
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.
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
Note: You must use DrScheme's HtDP Intermediate Student
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.
- 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)))
- Design a program that renders an "Enum" as an image:
The rendering program consumes an
(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
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.
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.
Finish problem 2.4.
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.