Professional Documents
Culture Documents
An Introduction to
Computer Science
Chapter 13
Algorithm Design and Recursion
Or n! 1 if n 0
n(n 1)! otherwise
This definition says that 0! is 1, while
the factorial of any other number is that
number times the factorial of one less
than that number.
curr = 1
prev = 1
for i in range(n-2):
curr, prev = curr+prev, curr
return curr
>>> hanoi(3)
Move disk from A to C.
Move disk from A to B.
Move disk from C to B.
Move disk from A to C.
Move disk from B to A.
Move disk from B to C.
Move disk from A to C.