SCXT 350
Exercise set #1
Due: Friday, Sept. 20 (in class)
Some exercises in LISP:
You are welcome (in fact, encouraged) to try out your solutions in
the lab, but please be prepared to do problems like these on an exam
without a computer handy.
Part I:
- Find the value of
- (+ 3 ( * 2 3))
- (/ 7 3)
- (/ 7.0 3.0)
- (* 6 (/ 7 3)
- (cons 'a '(x y z))
- (cons 'a (cdr '(x y z)))
- (cadr '(a b c))
- (cdr '(a b c))
- Write Lisp statements to calculate the following. Use only
car, cdr (and combinations), arithmetic expressions, and cons:
- (4 + 2) / 4
- 3 * 3 - 4 * 2 * 5
- Find the second item in a list; the third item in a
list
- Swap the first two items in a list
Part II: Write functions (using defun and if) to:
- Add two numbers
- Determine which of two numbers is bigger
- Determine the middle value of three numbers
- Return the second item in a list
- Return the third item in a list
- Swap the first two items in a list
- [Only if you have had CSci 161]
- Calculate the nth Fibonacci number (Fib(1) = 1, Fib(2) = 1,
Fib(n) = Fib(n-1) + Fib(n-2) for n > 2)
- Give a series of instructions for solving the towers puzzle
for a given number of disks.
Notes: Look at Part01.ppt in the CogSci handouts folder.
In our lab on Monday, try your solutions out. On Friday, Sept. 15,
turn in (in class) your written (word processor) solutions.