Homework for Dec 7 (due Dec 10)

  1. Do exercise 12 on page 208 (chapter 28).

  2. Using the code from class, write another Towers of Hanoi program (like regular, check, and watch) to count the number of moves that are made. It should return not only the finished Hanoi set, but also the total number of moves made, as a tuple. Make sure the reported number of moves matches what we would predict using the recurrence relation. (Hint: use a reference variable as a counter; have your hook function increment it.)

  3. We could write a function in ML to compute the fibonacci sequence like
    fun fibonacci(0) = 1
      | fibonacci(1) = 1
      | fibonacci(n) = fibonacci(n-1) + fibonacci(n-2);
    
    But that would be grossly inefficient. Instead, write a recursive fibonacci function in ML that does not redo work. (Hint: Use a helper function, and pass around a tuple standing for the two most recently computed items in the sequence. For more help, read Section 30.1 and look at Exercises 2 and 3 of Chapter 30 (pg 225)).

  4. Do exercises 1-3 on page 234 (chapter 31)

Thomas VanDrunen
Last modified: Wed Dec 5 10:51:13 CST 2007