A puzzle born as marketing
Édouard Lucas invented the Towers of Hanoi in 1883 and sold it as a wooden toy—complete with a myth about monks moving 64 disks for 264−1 moves.
Everything runs locally in your browser — no uploads, no accounts.
Tip: You can click the canvas anywhere—I'll pick the nearest peg.
Play manually with simple tap/tap moves, or watch Auto-Solve animate the optimal solution. Adjust the number of disks and the animation speed at any time.
2^n − 1 moves.Towers of Hanoi is a classic puzzle used in maths and computer science to teach recursion, problem decomposition, and algorithmic thinking. The goal is simple: move a stack of disks from Peg A to Peg C using Peg B as a helper, without ever placing a larger disk on top of a smaller one. Despite the calm visuals, the puzzle grows exponentially more complex as you add disks, which makes it perfect for step-by-step learning.
For n disks, the minimum (optimal) move count is:
2^n − 1. Examples:
• 3 disks → 7 moves
• 5 disks → 31 moves
• 8 disks → 255 moves
This comes from a recursive pattern: to move n disks, you must first move the top
n−1 disks to the helper peg, then move the largest disk to the target peg, and finally move the
n−1 disks onto it. In recurrence form:
T(1)=1, T(n)=2·T(n−1)+1, which solves to T(n)=2^n−1.
O(2^n), highlighting exponential growth.Use Manual mode to build intuition: tap a peg to pick up the top disk, then tap another peg to place it. When you want to check your understanding or demonstrate the algorithm, switch to Auto-Solve and adjust the speed. Watching the optimal sequence helps you recognise the recursive pattern.
Is there always a unique optimal solution?
Yes, for a fixed labelling of pegs and a fixed start/target, the sequence of moves achieving 2^n − 1 is essentially determined by the rules. Variations come from which peg you treat as the helper.
Why does it feel much harder at 7–8 disks?
Because the shortest solution more than doubles with each extra disk. Going from 6 to 8 disks jumps from 63 to 255 optimal moves.
What skills does this build?
Planning, attention switching, and an intuitive sense for recursion and exponential growth—useful in programming, electronics, scheduling, and more.
Tip: Start with 3–4 disks for quick wins. When your moves match the Optimal counter, increase disks by one and try again. Small, steady steps make the puzzle enjoyable.
Édouard Lucas invented the Towers of Hanoi in 1883 and sold it as a wooden toy—complete with a myth about monks moving 64 disks for 264−1 moves.
Even at one move per second, 264−1 moves take about 585 billion years—over 40× the age of the universe. That monk story was safe marketing.
The optimal solution traces a binary Gray code: each move flips exactly one bit in the disk-on-peg encoding, changing only one disk’s position at a time.
The puzzle’s recursive structure gives a textbook example for proof by induction—one of the cleanest “see the pattern, prove the pattern” demos in CS.
Because rules are strict and states are discrete, Towers of Hanoi often appears in AI planning and robotics courses as a gentle search/heuristics sandbox.