Tower of Hanoi: The Pattern to Solve Any Stack
The Tower of Hanoi has a fearsome reputation for such a tiny puzzle - a few disks on three pegs, and somehow it ties beginners in knots. The good news is that it is one of the most solvable puzzles ever invented: there is a clean pattern that works on three disks, ten disks, or a hundred, and once you see it you can never really get stuck again. This guide covers the two rules, the famous recursive idea that explains why it works, a dead-simple trick that lets your hands solve it without thinking, and the neat reason the answer is always the same number of moves. By the end you will be able to move any stack on autopilot.
The two rules
The whole puzzle runs on a single setup. You start with a stack of disks on one peg, largest on the bottom and smallest on top, like a little pyramid. Your job is to move the entire stack to a different peg. There are only two rules, and everything else follows from them:
You may move only one disk at a time - always the top disk of a peg - and you may never set a larger disk on top of a smaller one.
That second rule is the whole game. Because a big disk can never sit on a small one, you are constantly forced to "park" disks out of the way to free up the one you actually want, and the third peg exists exactly so you have somewhere to park them. The puzzle is not really about lifting disks - it is about clearing a path.
Try it tiny first. Three disks is the perfect teacher: it takes only seven moves to solve, so you can run the whole thing two or three times in a minute and feel the rhythm. Mochi Rings opens on small, gentle stacks for exactly this reason, with unlimited Undo so a wrong move costs you nothing while the pattern is still sinking in.
The recursive idea (the heart of it)
Here is the insight that makes everything click. Suppose you want to move a stack of N disks from the start peg to the goal peg. The biggest disk on the bottom can only go straight to the goal if the goal is empty and every smaller disk is out of its way. So forget the big disk for a moment and ask a smaller question: how do I get all the disks above it onto the spare peg?
That gives you a three-step plan that solves any stack:
- Move the top N minus 1 disks to the spare peg. Treat that smaller pile as its own little Tower of Hanoi and get it out of the way.
- Move the single biggest disk to the goal peg. Now it has a clear shot, and it never has to move again.
- Move the N minus 1 disks from the spare peg onto the goal peg. Stack them back on top of the big one, and the tower is rebuilt.
The clever part is that steps 1 and 3 are the exact same puzzle, just one disk smaller. To do them, you use the same three steps again on N minus 1 disks, which calls it again on N minus 2, and so on, all the way down until you are moving a single disk - which is trivial. That self-similar nesting is called recursion, and it is the reason the Tower of Hanoi is a classic teaching puzzle in mathematics and computer science. You never have to plan the whole solution; you only ever solve "move this pile aside, move the big one, move the pile back."
The simple alternating trick
Recursion explains why the puzzle works, but you do not want to be tracking a tower of nested plans in your head while you play. There is a much simpler way to actually solve it by hand, and it is almost mechanical. The whole solution is just two moves repeated over and over:
- Move the smallest disk. It always moves, and it always moves in the same circular direction (more on that below).
- Make the only other legal move. After moving the smallest disk, there is exactly one move available that does not involve the smallest disk again - so make it. There is never a choice to agonise over.
Then repeat: smallest disk, only-other-move, smallest disk, only-other-move, until the tower is rebuilt on the goal. That is the entire method. You alternate between the smallest disk and "the one move that is forced," and the puzzle solves itself.
The one thing to settle is which direction the smallest disk travels. Picture your three pegs in a loop. If your total number of disks is odd, the smallest disk should keep cycling one way around the pegs - start peg to goal peg to spare peg and back around. If the number of disks is even, send it the other way. Pick the right direction for your stack, always move the smallest disk that same direction every single time, and never deviate - the alternating "only other move" handles everything else automatically.
Why "every other move"? Notice that the smallest disk can never block anything (nothing is smaller than it), so it would be wasteful to move it twice in a row. Moving it on every other turn is exactly the cadence the recursive solution produces - the alternating trick is just the recursion in disguise, repackaged so your hands can run it without thinking. On Mochi Rings you can watch this rhythm appear on its own once the moves get smooth.
Why it always takes the same number of moves
One of the most satisfying facts about the Tower of Hanoi is that the fastest possible solution has a fixed length you can calculate in advance. For N disks, the minimum number of moves is 2 to the power of N, minus 1. Three disks take 7 moves, four disks take 15, five take 31, and ten disks take 1,023.
You can see why straight from the recursive plan. To move N disks you have to move N minus 1 disks aside, then move 1 big disk, then move those N minus 1 disks back - so the work for N disks is roughly double the work for N minus 1, plus that single middle move. Each extra disk almost doubles the total, which is exactly what powers of two do. There is no shortcut that beats it: the big disk genuinely cannot move until everything above it is parked, so the doubling is unavoidable.
This is also why the puzzle becomes a useful gut-check. If you finish a four-disk stack in 15 moves, you played it perfectly. If it took you 40, you were wandering - usually by moving the smallest disk twice in a row or sending it the wrong direction. The move count is an honest scorecard you can carry in your head.
Common mistakes
Almost every stall on the Tower of Hanoi comes from one of a handful of habits. Watch for these:
- Trying to plan the whole thing at once. You will never hold ten disks of strategy in your head. Think only "move the pile aside, move the big one, move the pile back," and let the smaller version take care of itself.
- Moving the smallest disk twice in a row. This is the single most common wasted move. The smallest disk goes on every other turn, never two turns running.
- Sending the smallest disk the wrong way. Once you commit to a direction (set by whether your disk count is odd or even), keep it constant. Switching direction mid-solve is how a tidy 15-move solution balloons.
- Forgetting where you are aiming. The goal peg never changes during a solve. If you start shuffling disks toward the spare peg as if it were the destination, you will undo your own progress.
- Panicking when a peg fills up. Disks parking on the spare peg is the plan working, not failing. They are meant to pile up there briefly before coming back.
Putting it together
Lay the pieces side by side and the Tower of Hanoi stops being intimidating. The two rules tell you what is legal; the recursive idea tells you why a solution always exists; the alternating trick gives your hands a way to play it without conscious effort; and the 2 to the n minus 1 count tells you the moment you have done it perfectly. The same four ideas scale from a three-disk warm-up to a towering stack - more disks just means more of the same rhythm.
The best way to lock it in is to solve a few small stacks back to back until the cadence feels automatic, then add a disk and notice that nothing about your method has to change. That is the quiet beauty of this puzzle: master it once at any size and you have mastered it at every size.
Where to go next
The fastest way to make all of this stick is to play it. Mochi Rings is the Tower of Hanoi dressed up as a shelf of glossy candy rings: tap a peg to lift its top ring, tap another to drop it, and rebuild the whole tower on the glowing goal peg without ever setting a big ring on a smaller one. It opens on gentle three-ring stacks so the alternating rhythm becomes second nature, then ramps up across twenty hand-tuned levels and five themed worlds - a fourth peg even joins later to give you real choices about where to park - before opening into endless generated towers. With unlimited Undo, no timer, and a gentle hint waiting if you stall, it is a forgiving place to feel the recursive pattern click. When you are ready for more brain-stretchers, try our guide to sliding puzzles or browse the full guides library.