Puzzle1-10 min
Tower of Hanoi
One disk at a time, and never a big one on a small one
How to play
- 1Pick the number of disks, 3 to 8, with the buttons at the top. Three or four is the place to start.
- 2Tap a peg to lift its top disk, then tap another peg to drop it there. Tapping the same peg again puts it back, and you can also drag a disk from peg to peg.
- 3A bigger disk cannot go onto a smaller one. It may only land on an empty peg or on a larger disk.
- 4Move every disk to the right peg to finish. Three stars for the minimum, two for anything up to one and a half times it, one beyond that.
- 5Stuck? Hint marks the disk to move next. It works out the fastest route from the position you are actually in, and a tower where you used a hint earns at most two stars.
- 6Auto-solve replays the shortest finish from the current arrangement one move at a time. Slow, Normal and Fast change the pace and pressing it again stops it. A tower that used auto-solve is kept out of records and stats.
- 7My record collects, per disk count, how many towers you finished, how many you finished in the minimum, your average move count and your day streak.
Controls
- Click / tap
- Pick a peg (lift, then drop)
- Drag
- Carry a disk from one peg to another
- Number keys 1-3
- Select the left, middle or right peg directly
- Left and right arrow keys + Enter or Space
- Click a peg or Tab into the board, then move between pegs and select
- Undo button / Z, Backspace
- Take back one move
- Hint button / H
- Mark the disk to move next
- Auto-solve button
- Play or stop the shortest solution
Tips
- The smallest disk moves on every other turn. Solve in the minimum and it moves on each odd-numbered move, while every even-numbered move is the single legal move that does not involve it.
- With an odd number of disks, send the smallest disk to the right peg first; with an even number, send it to the middle. After that the smallest disk simply keeps cycling in the same direction.
- Think in terms of the big disks. To move the bottom disk to the right peg, everything above it has to be sitting on the middle peg first.
- Each extra disk doubles the minimum and adds one. Once you can do four disks in 15 moves, five in 31 falls out of exactly the same method.
What is Tower of Hanoi?
Three pegs, with disks of different sizes stacked largest-first on the left one. Move them one at a time to rebuild the same stack on the right peg and you have solved it. Two rules, and that is all: only the top disk of a peg may be moved, and a larger disk may never sit on a smaller one.
The puzzle was introduced in 1883 by the French mathematician Edouard Lucas. With n disks the fewest moves possible is 2 to the power of n, minus one - so 7 moves for three disks, 15 for four and 255 for eight. Adding one disk slightly more than doubles the work, and this is a puzzle where you feel that with your hands rather than read it in a formula.
You never have to memorise a solution, because one idea solves any size. To move the bottom disk you must first move everything above it to the spare peg as a complete stack, and moving that smaller stack is the same problem again. Splitting a large problem into a smaller copy of itself is called recursion, and the Tower of Hanoi is the standard example of it.
While you play, the header shows the fewest moves still needed from the position in front of you. Add that to your own move count and you can see at a glance how far off the minimum you have drifted. Auto-solve replays the shortest path to the end from wherever the disks currently stand, at three speeds, and a tower that used it is left out of your records.
Frequently asked questions
How is the minimum number of moves fixed?
With n disks it is 2 to the power of n minus 1: 7 for three disks, 15 for four, 31 for five, 63 for six, 127 for seven and 255 for eight. It is proved that no shorter sequence exists.
Does the hint still work if I have made a mess of it?
Yes. The hint is not a replay of a memorised solution. It calculates the fastest next move towards the right peg from whatever arrangement the disks are in at that moment.
How are records kept?
The fewest moves is stored separately for each disk count. Moves you undid do not count. My record also shows, per disk count, how many towers you finished, how many you finished in the minimum, your average move count and how many days in a row you have played. All of it stays in this browser.
Does auto-solve count towards my record?
No. Auto-solve is there to be watched, so a tower on which you used it even once is left out of your best, your stats and your stars, and the result screen says so. Since it resumes from the current arrangement, it is quite reasonable to watch one or two moves at the point where you are stuck, stop it, and carry on yourself. Restarting puts that tower back in the records.
What is the legend about 64 disks?
Lucas attached a story to the puzzle: monks in a temple are moving 64 disks, and the world ends when they finish. At one move a second that is 2 to the power of 64 minus 1 seconds, roughly 580 billion years.