How to Play Tower of Hanoi
Tower of Hanoi is an internationally renowned mathematical puzzle invented in 1883 by French mathematician Édouard Lucas. Steeped in mythological lore regarding an ancient temple in Benares where monks move 64 golden discs, the puzzle is celebrated worldwide for its elegant demonstration of recursive thinking, exponential progression, and binary Gray codes.
- The Starting Configuration: You begin with three vertical pegs labeled Peg A (Source), Peg B (Auxiliary), and Peg C (Destination). A neat stack of graduated discs sits on Peg A, arranged in descending size with the largest at the bottom and the smallest at the top.
- One Disc at a Time: Only the topmost disc of any peg can be selected and moved during a turn.
- The Invariant Size Rule: A disc can only be placed on an empty peg or on top of a larger disc. You can never place a larger disc on top of a smaller one.
- Winning Condition: Successfully reconstruct the complete tower on Peg C in the minimal possible moves ($2^n - 1$).
Mathematical Strategies and Solving Algorithms
The beauty of Tower of Hanoi lies in its predictable, recursive symmetry. Solving the puzzle with zero wasted moves does not require memorization of random steps; rather, it hinges on understanding one of three systematic techniques:
1. The Recursive Divide-and-Conquer Algorithm
To transfer an $n$-disc tower from Source to Destination:
- Move the upper $n - 1$ discs from Source to Auxiliary.
- Move the single largest ($n$-th) disc directly from Source to Destination.
- Move the $n - 1$ discs from Auxiliary to Destination.
Because this process repeats recursively for smaller sub-towers, the total number of moves satisfies the recurrence relation $T(n) = 2T(n-1) + 1$, yielding the closed-form equation $T(n) = 2^n - 1$.
2. The Iterative Parity Rule
If you prefer solving without mental recursion, follow this simple parity rule based on whether your total disc count is even or odd:
- If $n$ is Odd: Make the very first move with the smallest disc to Peg C (Destination). On subsequent turns, alternate between moving the smallest disc clockwise ($A o C o B o A$) and making the only legal move that does not involve the smallest disc.
- If $n$ is Even: Make the very first move with the smallest disc to Peg B (Auxiliary). On subsequent turns, alternate between moving the smallest disc counter-clockwise ($A o B o C o A$) and making the only other legal move.
3. The Binary / Gray Code Connection
The sequence of moves corresponds directly to the counting sequence in binary Gray codes. The $k$-th move always shifts disc number $m$, where $2^{m-1}$ is the largest power of 2 that divides $k$. For example, on move 1 (divisible by $2^0$), you move Disc 1. On move 2 (divisible by $2^1$), you move Disc 2. On move 4 (divisible by $2^2$), you move Disc 3.
Game Features
📐 Multi-Disc Flexibility
Toggle between 3, 4, 5, 6, 7, and 8 discs to scale the difficulty from 7 moves up to 255 moves.
🤖 Interactive Auto-Solver
Watch the recursive algorithm execute step-by-step with smooth animations and pause/resume controls.
💡 Smart Move Hint
Instant shortest-path deduction suggests the exact next peg transfer without giving away the whole solution.
📱 Dual Touch & Drag Input
Tap-to-select and tap-to-place, or fluidly drag discs with physical pointer coordinates on mobile and desktop.
🔊 Harmonic Web Audio
Pitch-shifted disc lift tones, resonant wooden settling clacks, and error notifications with instant mute.
⭐ Par Star Rating & Best Records
Automatic tracking of best times and minimum move completions stored in browser local storage.