Developa function stutter
that takes
in a list of objects and returns a list twice as long with each
object appearing twice in a row. For example,
(check-expect (stutter (cons 3 (cons 8 (cons -2 empty)))) (cons 3 (cons 3 (cons 8 (cons 8 (cons -2 (cons -2 empty)))))))
Develop a function remove-all
that
takes a string and a list of strings and returns the same list with all
occurrences of the given string removed.
Example:
(check-expect (remove-all "bat" (list "doll" "bat" "bat" "nintendo" "bat" "ball")) (list "doll" "nintendo" "ball"))
Develop a function replace
that takes two strings (referred to as old
and
new
)
and a list of strings,
and returns a list of strings with old
replaced
throughout by new
.
Example:
(check-expect (replace "bat" "ball" (list "doll" "bat" "bat" "nintendo" "bat" "ball")) (list "doll" "ball" "ball" "nintendo" "ball" "ball"))
Develop a function named
add-vote-for
which takes in a string (the name of a candidate) and a list of
candidate structures, and returns a list of candidate structures
in which that candidate has one more vote (and all the others are
unchanged). You may assume that no name appears more than once in
the list of candidate structures.
Note: it's possible that the name doesn't appear in
the list
at all (e.g. it's a write-in vote, or something
like that);
if so, the resulting list should have 1 vote for that candidate.
Develop a function named
tally-votes
which takes in a list of strings (Voter 1's favorite candidate,
Voter 2's favorite candidate, etc.) and produces a list of candidate
structures
in which each candidate name appears once, with how many votes were
cast
for that candidate.
Write an animation of a bunch of balls,
each moving around the screen with constant velocity until they bounce
off a wall. Pressing the +
key should add one more ball,
with random initial location (inside the animation window) and random
velocity (say, from -10 to +10 in each dimension). Pressing the
-
key should remove the most-recently-added ball (unless
there are none, in which case it should do nothing). Clicking with
the mouse inside a ball should remove the ball you clicked on, but
leave all the rest of the balls unchanged.
Hint: you'll need each ball to have a location and a velocity, as in exercise 16.8.4 from homework 7, and you'll need a list of them, as in the animation from homework 8.
Extra credit: develop a function named
sort-candidates
which takes in a list of candidate
structs and produces a list of the same candidate structs, but with
the candidates sorted in decreasing order of number of votes (so the
one with the most votes is first in the list, and the one with the
fewest votes is last).
Extra credit: develop a function named
permutations
which takes in a list of things (strings, or
symbols, or numbers, or characters... it doesn't matter) and produces a
list of all the possible "scramblings" of that list. For
example,
(check-expect (permutations (list 'a 'b 'c)) (list (list 'a 'b 'c) (list 'a 'c 'b) (list 'b 'a 'c) (list 'b 'c 'a) (list 'c 'a 'b) (list 'c 'b 'a)))(Your function may return the answers in a different order, as long as it returns a list of all the possible answers, once each.)
All of the problems are programming problems. There is one animation; deal with it as you did in the previous few assignments.
Also turn in a log of how many errors of different kinds you encountered in the assignment, with brief comments describing each one ("mismatched parentheses" is self-explanatory, but more complex errors might need more description). Note that "errors" means not only error messages from DrScheme, but also wrong answers. You may do this using the PSP forms, or simply by keeping track in a text file or on paper and turning it in.
Error log: /30
(I'm not grading on how many or how few errors you encountered,
only on whether you recorded them correctly.)
I sha'n't actually grade all the problems; consider the others "practice". For each function I grade, see the table below, which has columns for each step in the design recipe. You won't turn in a separate skeleton, inventory, and definition, but rather write a skeleton, then add an inventory, then add a body to turn it into a complete definition. However, if you don't get the definition working, comment it out and you'll still get partial credit for a correct skeleton and/or inventory.
Contract | Examples | Skeleton | Inventory | Definition | Choice of model and handlers (for animations) |
Working animation (for animations) |
---|---|---|---|---|---|---|
/5 | /5 | /5 | /5 | /15 | /5 | /5 |
Following directions | /10 |
Writing contracts from word problems | /10 |
Choosing examples | /10 |
Choosing names | /10 |
Coding | /10 |
Code re-use and function composition | /10 |