← Back to Miscellaneous

The Tower of Hanoi

A puzzle from 1883, a recursive solution and a problem that is still open: try it with up to 15 disks and 10 pegs.

How to use

The goal is to move the whole tower from peg A to the last peg following two rules: move only one disk at a time, and never place a disk on a smaller disk. What is the minimum number of moves? That is for you to find out! This application accompanies my talk on what mathematicians do, where the tower of disks models a stack of fragile crates that a forklift must move from one dock to another. With it, you can:

  • play with the mouse, a finger or the keyboard, with 1 to 15 disks and 3 to 10 pegs;
  • fill in your own “How many moves?” table: each tower solved without help writes your best result in it, and a ✓ appears when you reach the minimum. Do you see the pattern? Can you guess the formula?
  • after 5 attempts, watch the optimal solution unfold, from 0.5 to 1000 moves per second, together with the recursive calls that build it and the hidden pattern of the disk that moves at each step;
  • add pegs: the strategy of Frame and Stewart (1941) was only proved optimal for 4 pegs in 2014, by Thierry Bousch; for 5 pegs or more, it is an open problem.

The “Hint” button shows the next optimal move from any position, the “Crates” look turns the disks into the crates of the warehouse, and a click in the “How many moves?” table starts the corresponding game. Press ? in the application for the complete help.

HTML, CSS and JavaScript application, created with the help of Claude Code (Anthropic).