CSci 431
Exercise set #1
Due: Monday, Sept. 18
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).
Points will be deducted for unnecessary input and output
statements, and for unnecessary use of local/global variables.
- 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 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.
- A node in a binary search tree consists of a data item (this
will be a number for now) and pointers to left and right subtrees.
We will implement this in LISP as (value left-tree right-tree)
where left-tree and right-tree are null or are binary search
trees. Do the following two exercises:
- write a routine which will list the nodes in order
- write a routine which will insert a node in the tree in the
appropriate place
Any questions? Please ask!