Tower of Hanoi

Move the whole tower to the right rod, one disk at a time, never a larger disk on a smaller one. Match the perfect 2^n − 1 moves!

How to play Tower of Hanoi

The Tower of Hanoi is the most famous logic puzzle in mathematics: three rods, a tower of disks stacked from largest to smallest, and one deceptively simple task — rebuild the whole tower on the far rod. Invented by the French mathematician Édouard Lucas in 1883, it hides a beautiful recursive structure behind three tiny rules. Anyone can solve the four-disk tower with a little patience; the eight-disk tower demands real discipline, because every disk you add doubles the length of the perfect solution. This version tracks your moves against the mathematical optimum and your time, and it runs entirely in your browser, online or offline.

The goal

Move the entire tower of disks from the left rod to the goal rod (marked with a star). The tower must end exactly as it began — largest disk on the bottom, smallest on top — just on a different rod. You win the moment the last disk settles on the goal rod; the fewer moves and the less time you take, the higher your score. Perfect play matches "par": on three pegs that is 2^n − 1 moves — 15 for four disks (Easy) and 63 for six (Medium). Hard uses a FOURTH peg with eight disks, where the extra rod cuts par all the way down to 33.

The setup

On Easy and Medium three rods stand side by side: left, middle and right. All disks begin on the left rod in a perfect pyramid. Your difficulty sets both the tower height and the number of rods — Easy is 4 disks on 3 pegs, Medium 6 disks on 3 pegs, and Hard 8 disks on 4 PEGS. The spare rods are your working space: the puzzle is impossible without at least one, and learning how to use them is the whole art of the game. A live move counter, the par (perfect-play) figure and the peg count are shown up top, and the timer keeps you honest.

The rules

  • Move one disk per turn. There is no way to shift two disks together — a tower moves only one slice at a time.
  • Only the TOP disk of a rod may move. Disks buried underneath are frozen until everything above them has been relocated.
  • A disk may never be placed on a smaller disk. Any disk may rest on an empty rod or on a larger disk — this single restriction is what makes the puzzle a puzzle.
  • To move: tap (or click) the source rod to lift its top disk, then tap the destination rod to drop it. Tap the same rod again to put the disk back down. Keyboard players can press 1, 2 and 3 for the left, middle and right rods, and U to undo.
  • The Undo button takes back your last move, all the way to the start if needed. Undone moves still count toward your move total, so a clean plan beats trial and error for score.

Winning

You win when all disks form a complete tower on the right rod. The banner shows your move count next to the optimal count, so you know exactly how close to perfection you came, and your score is submitted to the leaderboard. A tower completed on the middle rod does not count — the goal is the rod on the right, so plan your very first move with the finish in mind.

The four-peg challenge (Hard)

Hard is not simply a taller tower — it adds a fourth peg, turning the puzzle into the classic "Reve's puzzle" studied by Frame and Stewart in 1941. With a spare rod the best strategy changes fundamentally: instead of always shifting n−1 disks aside, you split the tower, park one group on the extra peg using all four rods, carry the rest with three rods, then reassemble. This Frame–Stewart method drops the eight-disk optimum from 255 moves (three pegs) to just 33 (four pegs) — proven optimal for four pegs in 2014. The par shown on Hard is this Frame–Stewart number, and your star rating grades how close you came to it.

The legend of the 64 golden disks

Édouard Lucas sold the puzzle with a marvellous story: in a great temple at Benares, priests labour over a tower of 64 golden disks resting on three diamond needles, moving one disk per second according to these same rules, day and night. When the final disk falls into place, the story goes, the world will end. There is no need to hurry to a bunker: 2^64 − 1 moves is 18,446,744,073,709,551,615 — at one move per second the priests need around 585 billion years, roughly forty times the current age of the universe. The legend survives because it captures the puzzle’s deepest lesson viscerally: exponential growth is unimaginably fast, and each extra disk doubles the work.

Strategy tips

  • Think recursively. To move a tower of n disks to the right, move the top n−1 disks to the middle, carry the biggest disk to the right, then move the n−1 tower on top of it. Every Tower of Hanoi, however tall, is just this one idea repeated.
  • Watch where the smallest disk goes. In a perfect solution the smallest disk moves every second turn and always circles in the same direction — with an even number of disks (as in all three levels here) it travels left → middle → right → left again.
  • Alternate moves. The optimal solution strictly alternates: smallest disk, then the only other legal move, then smallest disk again. If you ever move the same disk twice in a row, you have wasted a move.
  • Never undo progress with the big disks. The largest disk should move exactly once in a perfect game; the second largest exactly twice. If a big disk is bouncing back and forth, your plan has gone wrong — undo and regroup.
  • Learn the rhythm on three pegs, then rethink it on four. Four disks (15 moves) teaches the full three-peg pattern in a minute, and the same rhythm solves six disks in 63. Hard is different: with a fourth peg the obvious recursion is no longer optimal, so park a batch of small disks on the spare rod first (a Frame–Stewart split) and you can finish eight disks in just 33 moves.

Frequently asked questions

How is the score calculated?

Score = 10,000 − seconds elapsed − (your moves − optimal moves) × 10, with a minimum of 1 and a cap of 99,999. Every wasted move costs 10 points and every second costs 1, so accuracy matters about ten times more than raw speed. A perfect, instant solve would score 10,000. The score is submitted when you complete the tower, and your best per difficulty appears on the leaderboard when you are signed in.

What is the minimum number of moves?

On three pegs it is exactly 2^n − 1: 15 moves on Easy (4 disks) and 63 on Medium (6 disks). This is a proven minimum — the largest disk can only move when the n−1 smaller disks are parked on a single spare rod, which itself takes at least 2^(n−1) − 1 moves before and after. Hard breaks that formula by adding a fourth peg: eight disks then take a Frame–Stewart optimum of 33 moves, not 255. Either way the "Par" chip shows the perfect-play figure beside your count the whole game.

What do the difficulty levels change?

Easy and Medium change only the number of disks — 4 and 6 — on the usual three pegs, so the classic rules and the 2^n − 1 par apply. Hard is a genuinely different puzzle: 8 disks on FOUR pegs. The extra rod does not just make it longer, it changes the optimal strategy itself (the Frame–Stewart method), which is why Hard's par is 33 rather than 255. All the movement rules — one disk at a time, never a bigger disk on a smaller one — stay the same on every level.

What are "par" and the star rating?

Par is the fewest moves a perfect player needs: 2^n − 1 on the three-peg levels and the Frame–Stewart optimum (33 for eight disks) on the four-peg Hard level. When you finish, a star rating grades your move count against par — three stars for matching par, two for solving within one and a half times par, and one star for a looser solve. Par costs you nothing directly; it is simply the target the score formula and the stars measure you against.

Is the temple story with the 64 disks true?

It is a marketing legend written by Édouard Lucas himself, the puzzle’s inventor, when it went on sale in 1883 — there is no such temple. But the arithmetic in it is real: moving 64 disks takes 2^64 − 1 moves, and at one per second that is about 585 billion years. The story endures because it is the most vivid illustration of exponential growth ever attached to a toy.

Does it work offline?

Yes. Once the page has loaded, everything — the rods, the move validation, the counters and the timer — runs entirely in your browser with no internet connection. Scores you earn offline are stored on your device and upload automatically the next time you reconnect, if you are signed in.

View the Tower of Hanoi leaderboard

Related games

MinesweeperSudokuWord Search2048Mahjong SolitaireKlotski (Huarong Path)