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 right 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 right rod; the fewer moves and the less time you take, the higher your score. Perfection means 2^n − 1 moves: 15 for four disks, 63 for six, 255 for eight.
The setup
Three rods stand side by side: left, middle and right. All disks begin on the left rod in a perfect pyramid. Your difficulty sets the tower height — Easy is 4 disks, Medium 6, Hard 8. The middle rod is your working space: the puzzle is impossible without it, and learning how to use it is the whole art of the game. A move counter compares you live against the optimal solution, 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 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 on Easy, medal on Hard. Four disks (15 moves) teaches the full pattern in a minute. The same rhythm — no new tricks — solves six disks in 63 moves and eight in 255. Speed comes from rhythm, not rushing.
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?
Exactly 2^n − 1 for n disks — 15 moves on Easy (4 disks), 63 on Medium (6 disks) and 255 on Hard (8 disks). This is a proven mathematical minimum: the largest disk can only move when the n−1 smaller disks are parked on a single spare rod, which itself takes a minimum of 2^(n−1) − 1 moves before and after. The move counter shows this optimum beside your count the whole game.
What do the difficulty levels change?
Only the number of disks: Easy is 4, Medium 6, Hard 8. The rules never change. What changes dramatically is the length of the perfect solution — each extra disk doubles it plus one — and how much concentration it takes to keep your place in the pattern without wasting moves.
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.