1. Binary Trees
A friend missed class this past Monday and is completely clueless when it comes to binary trees. They managed to start the data definitions but got frustrated and gave up. Help them out!
;; A SBT (String Binary Tree) is one of
;; - (make-leaf)
;; - (make-node String SBT SBT)
(define-struct leaf ())
;; A Leaf is a (make-leaf)
;; INTERP: represents a leaf in a binary Tree
(define-struct node (val left right))
;; A Node is (make-node String SBT SBT)
;; INTERP: Represents a node in a SBT that has exactly 2 children.
2. List of List of Strings
You have another friend who actually attended class on Monday but spent the entire time on Facebook looking at their crush’s profile pictures from 2010. They need help with Lists of Strings. Use the following data definitions:
;; A List of Strings (LoS) is one
;; - empty
;; - (cons String LoS)
;; Template
;; los-fn: LoS -> ???
#;(define (los-fn los)
(cond
[(empty? los) ...]
[(cons? los) ... (first los) ...
... (los-fn (rest los)) ...]))
3. Playing with Big Bang
You are now at your 3rd job in 1 year (how fickle you are!). And once again, you are working on developing a game. Because you have so much work experience, your superiors have decided to put you in charge of moving a square around a screen! How exciting! You are given the following data definitions:
(require 2htdp/image)
(require 2htdp/universe)
(define-struct world (pin square-side))
;; A World is (make-world Posn NonNegInteger)
;; INTERP: represents the pin (location) of the center of the square and
;; the side of the square to draw
(define BACKGROUND (empty-scene 500 500))
(define INIT-WORLD (make-world (make-posn 250 250) 50))
Now, your team shares with you that they are very indecisive and the speed at which the square moves is probably going to change a couple times.
You are given the following code to test out your functions:
(big-bang INIT-WORLD
(on-tick move-left 0.1)
(to-draw draw-world))