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
;; - ‘leaf
;; - (make-node String SBT SBT)
(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 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. List of Posns
The team you are a part of is working on designing a game. In this game, little missiles move across the screen from left to right. You are in charge of keeping track of these missiles and their locations. You decide the best way to do this is to use a List of Posns. You are given the following incomplete data definitions from a previous team member who decided they had enough of Dr.Racket to pursue their passion of ceramics.
;; A Posn is a (make-posn Number Number)
;;; Template
;; posn-fn: Posn -> ???
#; ???
;; A List of Posns (LoP) is one of
;; - empty
;; - ???
;;; Template
;; lop-fn: LoP -> ???
#;???
Your team has now given you the width and height of the scene of the game (500 x 500). During the game, the missiles that exit the screen should be removed from the List of Posns.
4. More lists, more structs, and more posns
You are now on a team of graphic designers working on the newest version of Microsoft Paint. The current project involves designing simple shapes for the program. You are put in charge of quadrilaterals. You need to design something to keep track of the coordinates of each corner of the shape. So, you decide to create a struct that contains the four corners of the shape.
(define-struct corners (first second third fourth))
Since you performed so splendidly on the previous task, your team has decided to entrust you with the task of creating a List of Corners
!
5. 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))
;; A World is (make-world Posn Corners)
;; INTERP: represents the pin (location) of the center of the square and
;; the square to draw
(define BACKGROUND (empty-scene 500 500))
(define INIT-WORLD (make-world (make-posn 250 250)
(make-corners (make-posn 0 0)
(make-posn 20 0)
(make-posn 0 20)
(make-posn 20 20))))
For this game, you will be using Corners and LoCs. Assume that all Corners in the list are squares.
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))