ICS 171: Homework #3

1. (30 Points). Do Problem 9.3 on Page 291 of Touretzky. Your solution should use loop instead of recursion.

2. (30 Points) IMPORTANT Write a function called count-matches(l, e) that takes a list l and counts the number of times that e occurs in l. For example,

(count-matches '(x o space x)  'x) should equal 2
(count-matches '(x o space x)  'o) should equal 1
(count-matches '(x x space x)  'o) should equal 0

3. (20 Points) IMPORTANT Define a structure that represents a state of the tower-of-hanoi problem. Create a global variable *start-state* and initialize it to the start state.

4. (20 points). IMPORTANT Create a function move-a-to-b(state) that takes as input a state structure representing a state of the Tower of Hanoi problem and returns NIL if the top disk from peg A cannot be moved to peg B or a new state with the top disk from peg A moved to peg B. Hint: use can-move? from Homework #2

Hand in a single file concatenating a dribble file testing your functions and a listing of the functions.

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