Towers of Hanoi

Towers of Hanoi Animation

This Towers of Hanoi animation uses the <canvas> element and may not run in older browsers.

Speed Factor (0.1 .. 50):
Discs (1 .. 40): Pegs (3 .. 16):
Total Moves: 19 

This is an animation of the well-known Towers of Hanoi problem, generalised to allow multiple pegs and discs. You can select the number of discs and pegs (within limits).

'Get Solution' button will generate a random solution to the problem from all possible optimal solutions - note that for 3 pegs the solution is unique (and fairly boring). If the total number of moves is too big (currently limited to 512) the number of discs will be reduced to meet the limit. This is just to limit the download size and may be increased later.

Solution shown always moves from peg 1 to peg 2. The total number of moves is displayed, so you can count along if you dont believe it!

Playback speed can be adjusted using the 'Speed Factor' box. 'Show Solution' button will play back the last generated solution, so you can get an action replay by lowering the speed factor and pressing the 'Show Solution' button again,

Enjoy!

PS If your browser has a problem with the 3D animation, try selecting 2D.