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.) 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)).