Tower of Hanoi Puzzle

Your browser does not support the HTML5 canvas tag.
Number of discs:


The puzzle can be solved by a recursive algorithm. To move a stack of n discs from the source peg to the destination peg, do the following steps in order:

1. Move the top n-1 discs to the spare peg.
2. Move disc n to the destination peg.
3. Move the stack of n-1 discs on top of disc n.

This algorithm works because this reduces the puzzle of n discs to a puzzle of only n-1 discs. That in turn is reduced to a puzzle of n-2 discs, and so on until the puzzle is reduced to moving a stack containing only 1 disc, which is trivial.

For example, the solution for small number of discs are as follows:
1 discA→C
 
2 discsA→BA→CB→C
 
3 discsA→CA→BC→BA→CB→AB→CA→C
 
4 discsA→BA→CB→CA→BC→AC→BA→BA→C
B→CB→AC→AB→CA→BA→CB→C