Variant
Random Tower of Hanoi
The same rules from a position nobody arranged. Every disk onto tower C, in as few moves as you can — and the board knows exactly how few that is.
Move History & Timeline
0 / 0 moves
—No moves yet. Make your first move!
One scramble, everyone, every day
The daily challenge is a scrambled position too — but the same one for every player, with a streak to keep.
Play today's puzzle →Set the position yourself
The solver takes any arrangement you type in and returns the shortest solution from it, move by move.
Tower of Hanoi solver →On this page
Play a random position
The board above was dealt, not stacked. The rules are exactly the ones you already know — one disk at a time, only the top disk of a tower, never a larger disk onto a smaller one — and the goal is still every disk on tower C. Shuffle deals a new position; Reset puts the one you are playing back the way it was dealt.
Every arrangement of the disks across the three towers is a legal position, and that is worth a moment. You never have to check whether a scramble is valid, because within a tower the order is not a choice: the disks on it must run largest at the bottom, so a set of disks on a peg has exactly one legal arrangement. With 5 disks there are 35 = 243 positions in total, and all of them are reachable from all of the others.
Why a scrambled start is harder
It is not harder because the puzzle is bigger. A dealt position is usually closer to solved than a full stack is, and takes fewer moves. It is harder because the method everyone is taught stops applying.
The textbook recursion is a sentence about a stack: move the top n − 1 disks to the spare tower, move the largest disk across, bring the n − 1 back. Every step of it assumes the disks you are talking about are already in a pile. From a scramble they are not, and there is nothing to recite — which is precisely why this is the board that tells you whether you understood the idea or memorised its shape.
It also breaks the habit that makes people good at the ordinary game and no good at this one. On a full stack the first move is always the same, and with a little practice a player stops deciding anything at all. Here the first move is a question every time.
Solving from any position
There is a rule, it is short, and it gives the shortest solution every time. It is the same idea as the textbook recursion with the assumption taken out.
- Find the largest disk that is not already home. Everything larger is on tower C and beneath it, and can be forgotten about — nothing will ever move it again.
- It has to get to the goal tower, and to move at all it needs every smaller disk off its own tower and off the goal tower. There are three towers, so that leaves exactly one place for all of them. No choice is being made here.
- So solve that smaller problem first — put every smaller disk onto that one tower — then move the large disk across, and start again.
Because nothing in those three steps is a decision, no cleverer route exists: the position of the largest misplaced disk forces where everything else must be before it can move. That is what lets this board do something no other Tower of Hanoi site does — tell you the exact number of moves between the position on screen and a finished puzzle, from any position, at any time. It is the number in the readout under the statistics, and it is a fact rather than an estimate.
Press Hint on any dealt board and then work out why that is the move. It is always step 1 applied to whatever is in front of you.
How far from solved is it?
Here is the pleasant surprise. The average distance from a random position to a solved board is not an ugly constant that has to be measured — it is exactly two thirds of 2ⁿ − 1.
The proof is the rule above, counted. Work down from the largest disk:
- Each disk has one tower it needs to be on — decided by the disks larger than it.
- If it is already there, it costs nothing. If not, disk k costs 2k−1 moves: its own move, plus carrying the finished smaller stack back on top of it.
- A random deal puts each disk on each tower with probability one third, so each disk is already right one time in three and wrong two times in three.
The expected total is therefore two thirds of 2n−1 + 2n−2 + … + 1 — two thirds of 2n − 1.
| Disks | Positions | Average moves to solve | Worst case |
|---|---|---|---|
| 3 | 27 | 4.7 | 7 |
| 4 | 81 | 10 | 15 |
| 5 | 243 | 20.7 | 31 |
| 6 | 729 | 42 | 63 |
| 7 | 2,187 | 84.7 | 127 |
| 8 | 6,561 | 170 | 255 |
| 10 | 59,049 | 682 | 1,023 |
| 12 | 531,441 | 2,730 | 4,095 |
| 15 | 14,348,907 | 21,844.7 | 32,767 |
The worst case catches people out. 2n positions are the full 2n − 1 moves away — 32 of the 243 at 5 disks — and they are the ones where every disk is on a wrong tower. The two tidiest positions on the board, a complete stack on tower A or tower B, are among them. A board that looks like chaos has usually had several of its large disks accidentally settled, and settled large disks are where almost all of the work is.
The deals on this page are not quite uniform, for that reason. A genuinely uniform draw sometimes hands over a position that is over in five moves, which is not a puzzle — so anything under 2n−1 moves from solved is thrown back, and the deal is drawn again. That floor is what it costs to move the largest disk once, so every position you are dealt contains at least one full clearing of the stack above it.
What this is good practice for
Three things, and they are the three that carry over.
Reading a position. The single most useful habit in this puzzle is to stop looking at the disks and look for the largest one that is out of place. On a full stack that is always the bottom disk, so the habit never has to form; here it has to form on the first move. It is also the habit that makes the strategies page make sense.
Recursion that is not a shape. If you are learning recursion with this puzzle — and a great many people are — then solving from a scramble is the test of whether the idea landed. The recursive call in the textbook version is always hanoi(n − 1, …) with the same three towers permuted. From a dealt position you have to work out what the smaller problem actually is before you can call it, which is the part that matters and the part the template hides.
Not trusting how a board looks. The efficiency readout is unforgiving here in a way it is not on a fresh stack, because a scramble tempts you into a plausible-looking move that undoes a large disk's work. When it says you are four moves off optimal, you are four moves off optimal, and the number can never go back down.
When you want the same idea with a fixed puzzle and other people playing it, the daily challenge is one scramble a day, the same one for everybody. When you want to set the position yourself rather than be dealt one, the solver takes any arrangement and returns the shortest solution from it.
Questions about random starts
What is Tower of Hanoi with a random start?
It is the ordinary puzzle — same three towers, same rules, same goal of getting every disk onto the right-hand tower — except that the disks begin scattered across the towers instead of stacked on one. Every arrangement of disks across the towers is a legal position, because within a tower the order is forced: a bigger disk can never be above a smaller one, so there is only one way to arrange any set of disks on a peg.
Is a scrambled Tower of Hanoi harder than the normal one?
Harder to think about, and usually shorter to play. The textbook method — move n − 1 disks aside, move the biggest, bring them back — assumes the disks start in one stack, and from a scramble there is nothing to recite. You have to find the largest disk that is not where it belongs and work out where everything above it has to go, which is the actual idea behind the recursion rather than its shape. The average scrambled position is two thirds of a full game away from solved, so it takes fewer moves than a fresh stack.
How many moves does a random Tower of Hanoi position take?
Anything from one move to 2ⁿ − 1, and on average exactly two thirds of 2ⁿ − 1. For 5 disks that is 21 moves on average against a worst case of 31; for ten disks it is 682 against 1,023. The worst positions are not the messy ones: a complete stack on the wrong tower is as far from solved as any position can be.
How do you solve Tower of Hanoi from any position?
Find the largest disk that is not already on the goal tower. It has to get there, and to move at all it needs every smaller disk off both its own tower and the goal tower — which leaves exactly one tower for all of them. So the job becomes: put every smaller disk on that one tower, move the large disk across, and then solve what is left. Repeat, and each step is forced, so the route it produces is the shortest one that exists.
Does the solver work from a scrambled position?
Yes, and it plays the genuinely shortest solution rather than a solution that happens to work. Auto Solve, Hint and Step all run the rule above, which is optimal from any legal position — which is also why the board can tell you exactly how many moves you are behind a perfect game, instead of guessing.
Can I share a particular scrambled position?
Yes. Make a move and use Copy link in the statistics panel: the position is encoded in the URL as one letter per disk, so anyone who opens the link gets exactly the board you were looking at, at the size you were playing. That is what makes a position citable in a lesson, a forum answer, or a bug report.