How to play Tower of Hanoi
The Tower of Hanoi is one of the oldest and most elegant puzzles in mathematics. You start with three pegs and a neat stack of discs on the leftmost peg — each disc smaller than the one beneath it, forming a tidy pyramid. The challenge looks trivial and turns out to be a genuine test of planning.
Goal
Move the entire stack from the left peg to the right peg, rebuilt in the same order, smallest on top. The middle peg is yours to use as a temporary resting place along the way.
Rules
- Move only one disc at a time — always the top disc of a peg.
- A larger disc may never rest on top of a smaller one. This single rule is what makes the puzzle interesting.
Controls
Tap or click a peg to pick up its top disc; the disc lifts and waits. Tap a second peg to set it down there, or tap the same peg again to cancel and put it back. On a keyboard, press 1, 2, or 3 for the left, middle, and right pegs. You can pick how many discs to play with, from a quick 3 up to a demanding 8 — use the disc-count button to change difficulty.
Strategy
There's a beautiful recursive trick behind the perfect solution. To move a stack of N discs to a target peg, first move the top N−1 discs onto the spare peg, then shift the largest disc to the target, then move that N−1 stack on top of it. A simpler rhythm also works: always move the smallest disc every other turn, cycling it in one consistent direction, and on the turns in between make the only other legal move available.
The maths
The fewest moves needed for N discs is exactly 2ᴺ − 1. So 3 discs solve in 7 moves, 5 discs in 31, 7 in 127, and a full stack of 8 takes 255 perfect moves. Try to match the optimal count once you've learned the pattern.