CSci 431
Exercise set #1
Due: Friday, Sept. 20
Write solutions for the following problems in common lisp. Place your
results in a commented file (use ';' for comments) in the handins
folder on Plato. Your file name should be your email username
(without the "@ups.edu). Your name should be at the top of the file,
and the statement of the problem should preceed each solution.
Points will be deducted for unnecessary input and output
statements, and for unnecessary use of local/global variables. None
of these functions should make any changes to the arguments. You may
use helper functions, but these functions should be otherwise
self-contained.
None of these functions should make any changes to the
arguments
- Write a function with computes the average of two numbers
- Write a function (max2) which finds the maximum of two
numbers
- Write a function which swaps the first two elements of a
list
- Write a function that mimics the built-in append funct
ion of common lisp.
- Write a function that mimics the built-in reverse
function.
- Write a function that converts any atom in a list (including
sublists) to an 'x
- If we don't do Fibonacci in class, do the Fibonacci function.
If we do, find a reference for Ackerman's function and do
that.
- Write a function that makes sure that left parenthesis are
appropriately matched with right parenthesis. Since we can't use
parenthesis, use the atom l to indicate a left parenthesis,
and the atom r to indicate a right parenthesis. So
(parenthesis '(l l r l r r)) should return t, b ut
(parenthesis '(l r r l l r)) should return nil.
- Write a function that prints out instructions for the
celebrated Towers puzzle. Please note that this will require the
use of a format statement. The function should take four inputs:
number of disks to move, from-peg label, to-peg label, and
free-peg label. For example, to move 3 disks from peg 1 to peg 3,
we might type: (towers 3 1 3 2).
- The function maxmin works the following way: if it is given an
atom (assumed to be a number), it returns that number. If it is
given a list of numbers, it returns the largest number. If it is
given a list of lists (or a list of numbers mixed with lists), it
returns the largest number found by applying the function minmax
to the list. Minmax works in the reverse way. For example, (maxmin
'(3 5 2)) returns 5, as does (maxmin '(3 (5 7) 2)) and maxmin((4
3) ((4 5) (2 7)) (2 1)), and so on. This function is used in
two-person games in which a good board position for one player is
a poor position for another. (save this for next
exercise)
- Set operations can be mimiced in Lisp. Taking lists as sets
(remebering that member checks for set membership), write routines
for union, intersection, minus, and times (Cartesian product).
Remember that union is not append, since elements in a set are
only in there one time.
Any questions? Please ask!