Recursion
Tower of Hanoi online, scored against 2ⁿ−1
Move a stack of discs from the left peg to the right one, never resting a wider disc on a narrower one — free, no account, three to eight discs. The fewest moves possible is exactly 2ⁿ−1, so the board can tell you precisely how far off perfect you were: 31 moves for five discs, 255 for eight. Play it more than once and the page keeps the whole series in a table, because the gap between your first finish and your best is the only thing here a single attempt cannot show you.
- 100% free
- No signup
- 3 to 8 discs
- Optimum shown live
- Whole session tabled
Move the whole stack from peg A to peg C, one disc at a time, never putting a wider disc on a narrower one. With 4 discs the fewest possible moves is 15, and the board has 81 legal arrangements of which the perfect route visits 16.
One rule, and two consequences
- Move one disc at a time, always the top one of a peg, and never onto a narrower disc. The pegs are all the same height and hold as many discs as you like — that is the difference between this board and the Tower of London’s.
- The first consequence is the count: 15 moves for 4 discs, because moving n discs means moving n−1 out of the way, moving one, and moving the n−1 back.
- The second is that the smallest disc moves on every other move of a perfect solution, in one fixed direction around the three pegs. If you ever move it twice in a row, the run has already left the optimal path.
How to play Tower of Hanoi
One rule about disc sizes, and a move count that has an exact target.
Choose how many discs you want to fight
Each extra disc roughly doubles the job: three discs is 7 moves at best, five is 31, eight is 255. Three or four is a couple of minutes and a good way to feel the pattern; six and up is where people start losing track of which sub-stack they were in the middle of. The count is fixed for the whole series, because a curve drawn across two different disc counts is not a curve.
Press a peg to pick up, press another to put down
Only the top disc of a peg can move, and it will not go onto anything narrower than itself — an attempt to do that is refused with the reason, and counted separately as a rule slip rather than as a move. Keys A, B and C select the pegs and Z takes back the last move. An undo counts in your total, because a move you had to take back is a move the perfect solution did not need.
Finish, then play it again and watch the table
Completing the stack on peg C ends the attempt and shows your move count against the optimum, your solve time, your undos and your refused moves. Then the same board comes back. The row that matters is not the first one: the page reports the drop from your first finished attempt to your best, which is the shape of somebody learning the recursion rather than the shape of somebody already knowing it.
Technical specifications
| Disc counts | 3 to 8, chosen before the series starts. Optimal move counts are 7, 15, 31, 63, 127 and 255 — every step up doubles the work and adds one move |
|---|---|
| The optimum | 2ⁿ−1, computed on the page for whatever disc count you picked. It is a proof rather than a record: no arrangement of legal moves reaches the target in fewer, so a run that matches it cannot be beaten by anybody |
| Size of the board | 3ⁿ arrangements are legal, since each disc can sit on any peg and the size rule then fixes the stacking order. At five discs that is 243 positions, of which a perfect solution visits 32 — about one in eight |
| Move rules | One disc at a time, top of a peg only, never onto a narrower disc. Pegs have unlimited height here, which is what separates this board from the Tower of London's 3-2-1 pegs |
| What counts as a move | Every disc that changes peg, plus every undo. Refused moves — dropping a wide disc on a narrow one, lifting from an empty peg — are counted in their own column and never enter the move total |
| Series memory | Every attempt at the current disc count stays in a table for as long as the tab is open. Changing the disc count clears it; so does a reload, because nothing is written to storage |
| When an attempt is void | A solve interrupted by the tab losing the foreground is dropped rather than timed, since the duration would contain however long you were elsewhere. The move count is dropped with it, so a void row cannot flatter the series |
| Reference figures | The optimum, and nothing else. There is no published distribution of human move counts on this puzzle worth quoting, so the page compares you with the arithmetic and with your own earlier attempts |
Frequently asked questions
Why is 2ⁿ−1 the minimum, and how is it known?
Because moving n discs necessarily contains moving n−1 discs twice. To get the largest disc across, every smaller disc has to be out of its way on the spare peg — that is a complete n−1 puzzle — then the big one moves once, then the n−1 stack has to come back on top of it, which is another complete n−1 puzzle. So the cost T(n) is 2·T(n−1) + 1 with T(1) = 1, and that recurrence has exactly one solution: 2ⁿ−1. It is not the best result anyone has recorded; it is the smallest number a legal sequence can have.
Does taking a move back count against me?
Yes, and it is also reported on its own so you can see how many of your moves were reconsiderations. The reasoning is that the optimum is a count of disc movements, and a perfect solver never moves a disc they will have to move straight back. Hiding undos would let a run of thirty-one moves plus twenty undos be reported as perfect, which would make the headline number mean nothing. Refused moves are treated differently — those are attempts the board never allowed, so nothing happened to count.
Why does the page keep asking me to play again?
Because one move count is nearly uninformative and two are not. Somebody who already holds the recursion solves five discs in thirty-one moves the first time and every time; somebody meeting it fresh takes forty or fifty, then thirty-five, then thirty-one. Both people can produce the same first attempt, and only the second and third attempts separate them. The table is the measurement here — the difference between your first finish and your best is printed as a percentage, and it needs at least two finished runs to exist.
Is a low move count a sign of intelligence?
It is mostly a sign of having seen the trick, which is why this page frames the result as a learning curve rather than a score. Kotovsky, Hayes and Simon demonstrated in 1985 that puzzles built with exactly this structure — the same states, the same legal moves, the same minimum — become far harder or far easier depending only on how the rules are described to the solver. If restating the rules can move solution times that much while the mathematics stays fixed, then the number in front of you is partly about the wording above the board, and no honest version of this page can turn it into a rank.
How long does the eight-disc board actually take?
255 moves at best, which is about four minutes of steady clicking at a move a second and considerably longer in practice. That doubling is the whole point of the puzzle's fame: the legend attached to it in 1883 involved 64 discs, which is 18,446,744,073,709,551,615 moves, and at one move per second that is roughly 585 billion years — about forty times the current age of the universe. The arithmetic is the story, and it is why nobody has ever needed to norm this task.
What is the trick, if I want to stop searching and start solving?
Watch the smallest disc: in a perfect solution it moves on every other move, and always in the same rotational direction around the three pegs. Fill in the moves between by the only rule available — on each even-numbered move there is exactly one legal move that does not involve the smallest disc, so make it. That produces the optimal sequence without any recursion in your head at all, and if you ever find yourself moving the smallest disc twice in a row you have already stepped off the shortest path.
How is this different from the Tower of London task?
Different board, different constraint and a different measurement. Here the pegs are identical and the discs are not: the rule is about size, the target is always the same complete stack, and the minimum grows exponentially with the disc count. There the beads are identical and the pegs are not: they hold three, two and one, every problem has its own target arrangement, and the minimum is between two and six moves. The consequence is that this puzzle rewards seeing a recursive structure, while that one rewards looking before touching — which is why it measures the pause before your first move and this one does not.
The arithmetic behind the puzzle, and why it has no norm
Édouard Lucas put the puzzle on sale in 1883 with a story attached: a temple where priests were moving sixty-four golden discs, and the world would end when they finished. The story is the reason the puzzle is famous and the arithmetic is the reason it is still used. With n discs the shortest solution is exactly 2ⁿ−1 moves, and the board has exactly 3ⁿ legal positions, because every disc may sit on any peg and the size rule then decides the order within each stack. At five discs that is 243 positions and a perfect route through 32 of them; at eight discs it is 6,561 positions and a route through 256. The graph those positions form is a Sierpiński triangle, with the three complete-stack positions at its corners and the optimal solution running straight along one edge — which is a rather exact way of saying that almost every position you can reach is not on the way to anywhere.
That exactness is why the page prints no percentile, and the reason is different from the usual one on this site. Elsewhere a figure is missing because the norms are copyrighted or were collected with a pencil and an examiner. Here there is nothing to norm: the reference value is a theorem, so your move count is compared with a number that is right by construction and needs no citation beyond the recurrence. What a browser cannot supply is the other half — a distribution of human move counts, which would have to control for disc count, prior exposure, whether undo was available and how the rules were worded, and which does not exist in any form worth quoting.
The last of those is not a technicality. Kotovsky, Hayes and Simon built isomorphs of this puzzle in 1985 — monsters passing globes around under rules that generate an identical state space — and found that solution times moved enormously depending only on the cover story, while the mathematics stayed fixed. A task whose difficulty can be changed that much by rewording is a task whose scores belong to the wording as much as to the solver, so this page reports what it can defend: your count, the optimum, and the distance between your first finished attempt and your best. If you want the tower that was designed as a measurement rather than as a toy, the Tower of London test reads its stopwatch twice, once at your opening move; if you want a task where the rule itself keeps changing underneath you, the Wisconsin card sorting test is the one to run, and the digit symbol substitution test is the opposite case: a task with no structure to find at all, where the only thing left to measure is how fast you can look things up.
Why the target number is not in any table
The minimum is two to the power of the disk count, minus one. That is a theorem, not a norm, and a transcribed table of it would only be a table with potential typos in it.
Computed live for the board you are playing: 2⁵ − 1 = 31 moves at five discs, 2⁸ − 1 = 255 at eight.
One note on precision, since several pages on this site report reaction times and this one does not. The solve clock starts on the frame that paints the board and stops on the timestamp of the move that completes the stack, both from the same monotonic clock — but a solve lasts tens of seconds, so the display latency that matters elsewhere is a rounding error here. Times are reported in seconds, and no figure on this page is quoted to a precision finer than the thing being measured.
This is a measurement exercise, not a clinical assessment. It reports what you did on this page against a stated reference and nothing more — it cannot establish a planning deficit, ADHD or a learning difficulty. Only a qualified professional, working with more than a browser, can make that judgment.
Where your series is kept
Every number on this page is worked out by JavaScript running in the tab you are reading it in. Your answers, your reaction times and your score are never uploaded, logged or kept — which is also why the test carries on working after you disconnect from the network, and why nothing here can be held back behind an email address.
The board, the move history and the attempt table live in this tab’s memory and nowhere else — not in local storage, not in a cookie, not on a server. That is why changing the disc count or reloading clears the table, and why the copy button exists for anyone who wants to keep a series.