Skip to content

Tower of Hanoi

Move three to five disks across labelled pegs under the classic legal-move rule, with a verified minimum and complete keyboard support.

Privacy: your files never leave your device. All processing happens locally in your browser.

How to use

  1. 1.Choose three, four, or five disks, review the displayed minimum, and start the puzzle.
  2. 2.Select a source peg to pick its top disk, then select a destination that is empty or has a larger top disk; keys 1–3 use the same path.
  3. 3.Move the full stack to Target and compare your move count only with the verified puzzle minimum for that disk count.

About Tower of Hanoi

Tower of Hanoi is the classic three-peg planning puzzle presented as a small, accessible browser game. A stack begins on the Source peg with the largest disk at the bottom and the smallest disk at the top. Your goal is to move the entire stack to the Target peg. Only one top disk can move at a time, and a larger disk may never be placed on a smaller disk. Those rules and the minimum-move formula are reference facts rather than decorative copy, so this release pins them to the NIST Dictionary of Algorithms and Data Structures and independently cross-checks the recurrence with Stony Brook University.

Choose three, four, or five disks before starting. The corresponding verified minimums are 7, 15, and 31 moves. The general three-peg minimum is 2 raised to the number of disks, minus 1. The evidence fixture writes literal expected values for one through eight disks: 1, 3, 7, 15, 31, 63, 127, and 255. Tests compare the production formula with those externally authored values instead of generating an expected answer by calling the same formula twice. The selectable range stops at five so a complete human browser route remains practical and the release can prove that the game can actually be won.

To make a move, select a peg that has at least one disk, then select a destination peg. The first choice selects only the top disk and does not increment the move counter. Selecting the same peg again cancels. Selecting an empty source reports that there is nothing to pick up. If the destination has a smaller top disk, the game rejects the placement, preserves every peg and the move count, and keeps the original source selected so you can choose a legal destination. A legal placement changes exactly two peg stacks and increments the move count exactly once.

The board stores every peg from bottom to top. Release tests check after every move that each disk from 1 through n appears exactly once and that every nonempty peg is strictly ordered from larger at the bottom to smaller at the top. A full seven-move route for three disks is driven through the public state functions and must finish with all disks on Target. Stale interaction tokens, invalid peg numbers, input before Start, and all moves after completion are atomic no-ops. The same guarded choice path serves clicks, taps, and physical keys 1, 2, and 3.

When the final legal disk lands on Target, the game freezes and reports your moves beside the verified minimum. Matching the minimum awards 1,000 points. Additional legal moves reduce the recreational point total by 20 each, with a floor of 100. The points are a product rule, not part of the classic puzzle source and not a rating of planning ability. Restart returns to the three-disk setup and clears all moves. The shared shell may save a best local point value in your browser, but no attempt, move path, score, or identifier is uploaded.

The interface uses three labelled native buttons rather than drag-and-drop. This makes the same move model available to keyboard, touch, pointer, zoom, and assistive-technology users. Disk widths are visual, while each disk also has a text label. Peg names, disk counts, selection state, move count, minimum, rejection feedback, and the final result are available without relying on colour. The double-Escape boss screen blocks hidden peg and restart mutations until it is closed.

This is an entertainment exercise, not a clinical/IQ/cognitive assessment. It does not diagnose planning ability, measure intelligence, or show whether your brain has improved. A move count has no health, educational, employment, treatment, screening, eligibility, or professional interpretation. Familiarity with the recursive route changes performance immediately. Use the page as a transparent puzzle, not as an evaluation of yourself or anyone else.

Methodology & sources

Implement the NIST/Stony Brook three-peg rule with bottom-to-top arrays and a two-selection move. Reject empty sources, same-peg cancellations, stale tokens and larger-on-smaller placements without incrementing moves. Verify the external minimum formula against literal n=1..8 golden values, enforce disk uniqueness and descending peg order, and drive the exact seven-move three-disk winning route. The UI supports 3–5 disks; matching 2^n-1 moves awards 1,000 product points, with no cognitive interpretation.

Frequently asked questions

What is the minimum number of Tower of Hanoi moves?
For the classic three-peg puzzle it is 2^n - 1. That gives 7 moves for three disks, 15 for four, and 31 for five.
What happens if I try to put a larger disk on a smaller disk?
The move is rejected without changing the board or move count. The selected source stays active so you can choose another destination.
Does solving Tower of Hanoi measure planning ability or intelligence?
No. This is a recreational puzzle with no norm group, assessment protocol, diagnostic meaning, or professional interpretation.

Mini Games guides

View all