Apps Games Sync Setup Docs About Help |
Hanoi Example
Hanoi is a good example of "recursion" (even though the actual underlying algorithm is implemented iteratively for better process control).
With the situation of 3 disks starting on left stack: If you knew how to move the top 2 disks somewhere else, e.g., to the middle stack, [steps 1-3 below], all you would have to do then is move the bottom disk to the right [step 4]; and since you already know how to move 2 disks, just move those from middle to right [steps 5-7].
Here are step-by-step directions for 3 disks (#1 refers to smallest disk) and 3 stacks (left,middle,right):
You can watch the program do this by setting method to Move.
toc |