2019-10-04
Directions: You may not consult any sources, including your old homework.
Bonus +5% if all functions have at least one (nontrivial) associated test case. Functions that are not complete but have three tests that outline an approach to creating the function will receive half credit.
-
(
some13
) Inputs: two numbersn
,c
. Output a list of the firstc
numbers aftern
that leave a remainder of 2 when divided by 13. Skip multiples of five, if there are any. -
(
collatz1
) Given a list of numbers, change every odd number $n$ to $3n+1$ and change every even number $n$ to $n/2$. Put out a list. -
(
word-table
): Given a list of symbols, create a list of pairs(list symbol count)
showing how many times each symbol appears in the list. The pairs may appear in any order in the result.(word-table '(dog cat elephant dog dog mouse mouse)) => '((dog 3) (cat 1) (elephant 1) (mouse 2))
-
(
live-ants
) Given a two lists of points in the plane,poison
andants
. Return a list of all of the ants that are at least distance 5 from every point in thepoison
list.
Stuck in the Mud
These are the rules for the dice game Stuck in the Mud:
-
The first player rolls all five dice. If any 2s or 5s are rolled, no points are scored for this throw. If no 2s or 5s are rolled, add up the total of the dice and write it down.
-
The player sets aside any 2s and 5s, and throws the remaining dice. Again, if any 2s or 5s are thrown, no points are scored. If there are no 2’s or 5s, add the total to the previous score.
-
Continue in this way until all the dice are “Stuck in the Mud.” After the score is totaled, play passes to the left.
You are going to write a simulator for stuck in the mud.
-
stuck-list
: Output a list containing a list of each roll made. Example:(stuck-list)
produces:'((2 5 6 3 6) (4 3 1) (3 4 5) (1 1))
-
stuck-score
: Take in a “stuck list” (as produced above) and produce the score for the person who rolled that sequence of rolls.
Starter Code
(ql:quickload :lisp-unit)
(use-package :lisp-unit)
(setf *print-failures* t)
(defun dist (x1 y1 x2 y2)
(sqrt (+ (expt (- x1 x2) 2)
(expt (- y1 y2) 2))))