Incode Systems Home Page Incode Systems, Inc.


HANOI



This program solves the "Towers of Hanoi" game involving 3 peg with increasingly larger disks stacked on the leftmost peg, smallest on top.

The object of the game is to move all the disks to the rightmost peg stacked with smallest on top. Rules are: only one moved at a time, can never place a larger disk on top of a smaller one.

Enter number of disks: 3

-------Move: 0 Level: 0
1: 3 2 1
2:
3:
-------Move: 1 Level: 3
1: 3 2
2:
3: 1
-------Move: 2 Level: 2
1: 3
2: 2
3: 1
-------Move: 3 Level: 3
1: 3
2: 2 1
3:
-------Move: 4 Level: 1
1:
2: 2 1
3: 3
-------Move: 5 Level: 3
1: 1
2: 2
3: 3
-------Move: 6 Level: 2
1: 1
2:
3: 3 2
-------Move: 7 Level: 3
1:
2:
3: 3 2 1
Highest Recursion Level = 3
Number of moves = 7