ICS 171: Homework #1

A. (50 points) Type the following things to lisp. Look up things you don't understand in Touretzky's book, on-line help.

(dribble "HW1.trace")
(defparameter *numbers* '(1 2 3 4 5))
(car *numbers*)
(first *numbers*)
(cdr *numbers*)
(rest *numbers*)
*numbers*
(setq *numbers* (cdr *numbers*))
(cons 1 *numbers*)
*numbers*
(setq *numbers* (cons 1 *numbers*))
(+ (first *numbers*)(second *numbers*))
(> (first *numbers*)(second *numbers*))
(< (first *numbers*)(third *numbers*))
(append *numbers* (reverse *numbers*))
(defun last-element(l) (car (last l)))
(last-element '(a b c))
(last-element (last-element '(a (b (c)))))
(defun sorted?(list)
  (or (null (cdr list))
      (and (< (first list) (second list))
           (sorted? (cdr list)))))
(sorted? *numbers*)
(sorted? (append *numbers* *numbers*))
(dribble)

B. (15 points) Load the files "minimax" and connect-four". Type the following commands to lisp

  
(dribble "game.trace")
(play)  
(dribble)

After you type "(play)", the computer will print a connect four board and wait for you to type a number 0 to 6 indicating your move. When you make a move, an X will appear in the lowest unoccupied square of the column you indicated. After your move, the computer will make a move, and wait for your next move. This repeats until one of you wins. You win if you get four X's in a row (horizontally, vertically or diagonally) and the computer wins if it gets four O's in a row.

C (25 points). Create a file containing the definition of one function "add-to-end" that takes two arguments. The first can be any thing and the second must be a list. add-to-end should create a new list by adding the first argument to the end of the second. My definition of add-to-end uses the lisp built-in functions append and list. Load your file into lisp and test it as follows

(dribble "end.trace")
(add-to-end  5 '(1 2 3))   ;; should evaluate to (1 2 3 5)
(add-to-end '(5) '(1 2 3))  ;;should evaluate to (1 2 3 (5))
(add-to-end 5 (add-to-end 4 '(1 2 3))) ;;should evaluate to (1 2 3 4 5)
(dribble)

D. (10 points) Find an electronic copy of the assignment for Homework #2 by using mosaic (from Suns or Xterms), lynx (from unix on terminals) or Netscape 1.0N

 mosaic http://www.ics.uci.edu/~pazzani/171-p.html 
(File, Save As- when viewing homework) from Suns or Xterms,
   lynx http://www.ics.uci.edu/~pazzani/171-p.html 
(d -when on link to homework) from from Unix with a terminal, or

Netscape 1.0N (File, Open Location http://www.ics.uci.edu/~pazzani/171-p.html)
(File, Save As- when viewing homework) from macs

E. Use a text editor to concatenate the text for Homework #2, the files you created "end.trace" "game.trace" "HW1.trace" and the file containing your definition of add-to-end and place it in the drop box or mail it to ics171ta.


Back to http://www.ics.uci.edu/~pazzani/171-p.html (text only) or http://www.ics.uci.edu/~pazzani/171.html .

Michael Pazzani
Department of Information and Computer Science,
University of California, Irvine
Irvine, CA 92717-3425
pazzani@ics.uci.edu