This is individual work. You are not allowed to spend more than 8 hours on this test. This includes any reading that you do to help you solve the problems.
Make sure to write your name in the file(s) you submit. You may submit one or two files.
Use helper functions as needed.
All your functions (including all those you use
in big-bang
) must have documentation with the types of
parameters and results, a function description, and, whenever
possible, check-expect
tests.
When defining your own structures, clearly explain what all the fields mean.
Comments, helpful variable names, and good code style and formatting
are a very important part of your grade. You don't have to look for the
shortest solution, but you should eliminate unnecessary code repetition if
possible (use helper functions).
Write a function even-length?
that consumes a
list and returns #true
if the list has an even number of elements
and #false
otherwise. Do not use the function
length
.
The function must pass the following check-expects:
(check-expect (even-length? (list 1 2 3)) #false)
(check-expect (even-length? (list 2 1)) #true)
(check-expect (even-length? (list 2)) #false)
(check-expect (even-length? (list "hi")) #false)
(check-expect (even-length? (list "hi" "bye")) #true)
(check-expect (even-length? empty) #true)
Think of how the return value of the function changes when one element
is added to the list: if you know the result for the rest of the list,
what is the result for the entire list?
Your task is to write a world in which the world state is a list of structures representing boxes. The structures are defined as follows:
(define-struct box [side x y])
;; Interpretation: side is the length of the side of a box,
;; x and y are the coordinates of the center of the box.
The world starts off with an empty list of boxes, and then boxes are added to form a tower in which each next box is added on top of the previous ones.
Assuming the canvas of 400 by 400, the list of boxes
(list (make-box 80 200 170) (make-box 90 200 255) (make-box 100 200 350))
will produce the following picture:
You may use this list as the starting state for testing.
Your goal is to implement the following:
height
that takes a list of boxes and
returns the height of the tower of these boxes. For instance,
for the above list the function returns 270.
height
function that you wrote earlier is helpful for
figuring out the y coordinate(make-box 70 200 95)
. If your rendering function works as
it should, the picture would look like this:
If something is not working, please comment it out and write comments about why you think it's not working and how you would be going about fixing it if you had more time. Make sure that the code you submit runs, even if it doesn't implement all of the functionality.
Your work will be graded based on:
Submit all your files as attachements in an email to me with the subject "Midterm 2" followed by your name or initials. Please include your name and a task number at the beginning of each file, in a comment. In your email message please include any comments about what works and what doesn't, as well as thoughts on how you would've continued if you had more time (if you run out of time). Also please include the total time you spent on the test.