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 and also name the files with your last name (and initial if needed). 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.
Some problems provide test cases, but you need to add your own to test thoroughly.
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 all-smaller?
that takes two lists of numbers
and returns #true
if each element of the first list is smaller
than the corresponding element of the second list (so the first element of the first list
is smaller than the first element of the second list, etc.). If one of the lists is shorter
than the other one, the extra elements aren't considered.
.
The function must pass the following check-expects:
(check-expect (all-smaller? (list 1 6 0) (list 2 8 1)) #true)
(check-expect (all-smaller? (list 1 6 0) (list 2 8 1 -5)) #true)
(check-expect (all-smaller? (list 1 6 0) (list 2 5 1)) #false)
(check-expect (all-smaller? (list 1 6 0) (list 2 6 1)) #false)
Write a function drop
that takes a list and a number n and
returns the list without the first n elements. If a negative number is passed to it,
the function produces an error. The check-expects below detail the function further:
(check-expect (drop 2 (list 1 2 3 4 5)) (list 3 4 5))
(check-expect (drop 0 (list 1 2 3 4 5)) (list 1 2 3 4 5))
(check-expect (drop 5 empty) empty)
(check-expect (drop 10 (list 1 2 3 4 5)) empty)
(check-error (drop -1 (list 1 2 3 4 5)) "cannot drop a negative number of elements")
Your task is to write some functions and a world in which the world state is a list of structures representing events. For simplicity the events start and end on the exact hour (so we can't have something like 10:30) and we use military time (10pm is represented as 22, midnight is 0). The structures are defined as follows:
(define-struct event [name start end])
;; Interpretation:
;; name is a string: the name of the event
;; start is an integer between 0 and 23 (inclusive): the start hour of the event
;; end is an integer between 0 and 23 (inclusive): the end hour of the event
;; Example:
(make-event "Meeting" 10 11)
No events extend past midnight.
Your task is to write several functions for lists of event
structures. Some of them include world programs, and some don't. The functions
that you need to write are:
#true
if
the given event overlaps with at least one of the events on the list, and
#false
otherwise.
Two events overlap if the starting hour of one is smaller than the
ending hours of another (say, one is 8 to 10, and the other one is 9 to 10).
If the starting hour of one is exactly the starting hour of another one,
they do not overlap (example: 8 to 10 and 10 to 11).
#true
if any event on the first list overlaps with any
event on the second list, and #false
otherwise.
(list (make-event "Meeting" 10 11) (make-event "Lecture" 13 15) (make-event "Movie" 21 23))
the result 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 via Canvas. Also please include the total time you spent on the test in a submission comment.