Tower of Hanoi

Mathematical disc-stacking puzzle — move stack of discs from source peg to destination peg via auxiliary peg, one disc at a time, never placing larger on smaller. Invented 1883 by French mathematician Édouard Lucas. Minimum moves = 2ⁿ−1 (7 discs = 127 moves, 8 = 255). Classic algorithm demonstration + brain teaser.

📐3 pegs + discs setup~15 min🌤indoor

What is Tower of Hanoi?

Tower of Hanoi is a mathematical puzzle invented in 1883 by French mathematician ÉDOUARD LUCAS. LEGEND accompanying original: monks at Brahma temple must transfer 64 golden discs; when complete, world will end. Actual minimum moves for 64 discs = 2^64 − 1 = 18,446,744,073,709,551,615 (~585 billion years at 1 move/second — universe safe!). GAMEPLAY: 3 vertical PEGS + n DISCS of DIFFERENT SIZES stacked on source peg (smallest on top). GOAL: transfer entire stack from source peg to destination peg via auxiliary peg. RULES: (1) MOVE ONE DISC AT A TIME. (2) Never place LARGER disc on SMALLER. (3) Discs move between the 3 pegs. MATHEMATICAL SOLUTION: minimum moves = 2^n − 1 where n = number of discs. (1 disc: 1 move; 3 discs: 7; 7 discs: 127; 10: 1023; 20: 1,048,575). RECURSIVE ALGORITHM: To move n discs from A to C via B: (1) Move n−1 discs A → B (recursive). (2) Move nth disc A → C. (3) Move n−1 discs B → C (recursive). Fundamental example of RECURSION in computer science curriculum globally. VARIANTS: (1) Standard 3-peg. (2) 4-peg (Reve's puzzle / Frame-Stewart algorithm). (3) N-peg generalizations. (4) COLORED discs with constraints. (5) 3D tower variants. HISTORICAL: Lucas' original 1883 marketing packaging featured Brahma legend. Toy still sold worldwide as 'Tower of Hanoi.' Standard puzzle in mathematics education + computer science algorithms courses.

Quick facts

Category

Puzzle Games

Type

Individual

Players

1–1

Duration

~15 min

Where played

indoor

Field / court

3 pegs + discs setup

Country of origin

🇫🇷 France

Estimated origin

Invented 1883 by Édouard Lucas (French mathematician); Brahma legend marketing invention (not historical); standard CS + math education example

Olympic

No

Popularity

global

How it works

Objective

Transfer entire stack from source peg to destination peg in minimum moves (2^n − 1).

Match structure

Solo puzzle; competitive: fastest completion or fewest moves.

Rules

Basic rules

  • 3 pegs + n discs

    Start: all discs on source peg, smallest on top.

  • Move one disc at a time

    Take top disc from any peg + place on another peg.

  • Never larger on smaller

    Placed disc must be smaller than disc it lands on (or empty peg).

  • Goal: transfer to destination peg

    Complete when all discs on destination peg in original order (largest bottom).

  • Minimum moves = 2^n − 1

    n = disc count. Provably optimal.

Advanced rules

  • Recursive algorithm

    To move n from A to C via B: (1) Move n−1 A→B, (2) Move n A→C, (3) Move n−1 B→C. Elegant divide-and-conquer.

  • Iterative algorithm

    Alternative approach: on odd moves move smallest disc cyclically; on even moves make only legal non-smallest move.

  • Frame-Stewart algorithm (4-peg)

    4-peg variant reduces optimal moves; algorithm 1941; still unproven optimal in general.

  • Colored disc variants

    Add constraints (no adjacent same colors); increases difficulty.

  • N-peg generalizations

    5+ pegs studied mathematically; some patterns unknown.

  • Brahma legend calculation

    64 discs = 2^64 − 1 = 18.4 quintillion moves. At 1 move/sec = 585 billion years. Universe age ~14 billion years.

Scoring

Solve in minimum moves (2^n − 1). Competitive: fastest time.

ActionPoints
Complete transferSuccess
Minimum moves (2^n − 1)Optimal solution
Extra moves (beyond minimum)Sub-optimal (add to move count)
Fastest timeCompetitive winner

Win condition · Transfer all discs from source to destination peg with min moves (2^n − 1).

Playing area

Called

3 pegs + discs setup

Dimensions

Physical set: 15-25 cm base with 3 pegs 8-15 cm tall. Digital versions abundant.

3 vertical pegs mounted on flat base; graduated-size discs (5-10 typical for physical toys).

Equipment

  • Physical Tower of Hanoi set

    $5-30 for wooden/plastic set with 5-10 discs. Educational supply stores + toy stores.

  • Digital app/web version

    Free apps + web solvers abundant. Educational + interactive.

  • 5-10 discs standard

    More discs = exponentially longer (2^n−1 moves).

Officiating

Casual puzzle; no governing body.

  • No formal officiating

Strategies

  • Recursive method (mental)

    Break down: move n-1 discs to auxiliary → move nth disc to destination → move n-1 from auxiliary to destination. Recursion elegant + optimal.

  • Iterative method (physical)

    On odd moves: smallest disc moves cyclically (peg A→B→C→A...). On even moves: only legal non-smallest move exists. Deterministic + optimal.

  • Practice small first (3-5 discs)

    Master 3-disc (7 moves) then 5-disc (31 moves) to internalize recursion pattern.

  • Don't attempt 10+ discs manually

    10 discs = 1023 moves = 30+ min tedium. Use for educational understanding, not solving.

  • Study computer science algorithms course

    Tower of Hanoi = canonical recursion example; understanding it clarifies broader algorithmic thinking.

  • Brahma legend fun fact

    64-disc theoretical takes 585 billion years — great for illustrating exponential growth.

Terminology

Tower of Hanoi
The puzzle itself.
Peg / Rod
Vertical post holding discs.
Disc
Circular graduated-size piece to move.
Source peg
Starting peg with all discs.
Destination peg
Target peg for complete stack.
Auxiliary peg
Middle peg used for temporary storage.
Recursion
Algorithmic technique: solve smaller version, then combine. Tower of Hanoi = canonical example.
Frame-Stewart algorithm
4-peg variant algorithm; still unproven optimal in general.
Brahma legend
Fictional monk legend; part of Lucas' 1883 marketing.
2^n − 1 minimum moves
Mathematical minimum for n discs.
N. Claus de Siam
Lucas' pseudonym under which puzzle first sold (anagram of 'Lucas d'Amiens').

Major competitions

  • No formal competitions; educational + brain-teaser use

    N/A · worldwide (educational)

Where it is played

Governing bodies

  • No formal federation

    N/A

Famous names & records

Famous athletes

  • Édouard Lucas (France, 1842-1891) — French mathematician; invented Tower of Hanoi 1883
  • N. Claus de Siam (Lucas' pseudonym) — Under which the puzzle was originally sold ('Claus' anagram of Lucas)
  • Various computer science textbook authors — Puzzle featured in every algorithms course
  • Frame + Stewart — Mathematicians who developed 4-peg variant algorithm 1941

Records

  • Tower of Hanoi invention

    Édouard Lucas1883 France (published under pseudonym N. Claus de Siam) (1883)

  • Brahma legend created

    Lucas marketing1883 (fictional monk legend, not historical) (1883)

  • Frame-Stewart algorithm (4-peg)

    Frame + Stewart1941 (unproven optimal in general) (1941)

  • Standard CS education example

    Computer science curriculaFeatured in virtually every algorithms course worldwide (2000)

  • Fastest human 7-disc solve

    Various online solversUnder 30 seconds (2020)

Learn this sport

beginner

  1. 1

    Buy or download 3-5 disc Tower of Hanoi

    $5-15 physical set or free app.

  2. 2

    Solve 3-disc (7 moves) manually

    Basic pattern recognition.

  3. 3

    Solve 5-disc (31 moves)

    Practice recursion mentally.

intermediate

  1. 1

    Solve 7-disc (127 moves)

    15-30 min manual solve; test recursive intuition.

  2. 2

    Study recursive algorithm formally

    Write program (Python, Java) to solve Tower of Hanoi; teaches recursion.

  3. 3

    Try 4-peg Reve's puzzle

    Frame-Stewart algorithm; more discs solvable in less time.

advanced

  1. 1

    Study n-peg generalizations

    5+ pegs; unsolved mathematical problems.

  2. 2

    Colored + restricted variants

    Add constraints; increases difficulty.

  3. 3

    Teach computer science students

    Standard curriculum example; explain recursion clearly.

Frequently asked

What is the Tower of Hanoi?+

Mathematical disc-stacking puzzle invented 1883 by French mathematician Édouard Lucas. 3 vertical PEGS + n graduated-size DISCS. Goal: transfer entire stack from source peg to destination peg via auxiliary peg. RULES: (1) Move ONE disc at a time. (2) NEVER place larger disc on smaller. (3) Use any peg. MINIMUM MOVES = 2^n − 1 (mathematically proven optimal). Legend from Lucas: monks at Brahma temple transfer 64 discs; complete = end of world. Reality: 64 discs = 18.4 quintillion moves = 585 billion years at 1/sec. Universe safe. Standard example in computer science recursion courses.

How do you solve Tower of Hanoi?+

RECURSIVE ALGORITHM (elegant): To move n discs from Source to Destination via Auxiliary: (1) MOVE n−1 discs Source → Auxiliary (recursive call). (2) MOVE nth disc (bottom largest) Source → Destination. (3) MOVE n−1 discs Auxiliary → Destination (recursive call). ITERATIVE ALGORITHM (physical): (1) On ODD moves: move smallest disc cyclically (A→B→C→A...). (2) On EVEN moves: only ONE legal non-smallest move exists — make it. Both algorithms produce MINIMUM 2^n − 1 moves. 3 discs = 7 moves. 5 = 31. 7 = 127. 10 = 1023.

Why is Tower of Hanoi important in computer science?+

CANONICAL EXAMPLE of RECURSION — 'solve smaller version of same problem then combine.' Featured in virtually every algorithms course + textbook (Cormen, Sedgewick, Kleinberg-Tardos). WHY TAUGHT: (1) DIVIDE-AND-CONQUER paradigm foundation. (2) SIMPLE PROBLEM, elegant recursive solution. (3) EXPONENTIAL COMPLEXITY (2^n) illustrates growth. (4) STACK MEMORY concepts (recursion depth). (5) PROOF BY INDUCTION natural. (6) MATHEMATICAL RIGOR (provably optimal solution). Alternative teaching examples: Fibonacci sequence, factorial, merge sort, quick sort. Tower of Hanoi arguably most memorable due to concrete visual + shocking exponential growth from 3 discs (7 moves) to 30 discs (1 billion moves).

What is the Brahma legend?+

FICTIONAL BACKSTORY invented by Édouard Lucas 1883 to market the puzzle. LEGEND: At Brahma temple (India / Vietnam depending on version), monks tirelessly transfer 64 golden discs across 3 diamond pegs, following puzzle rules. When complete, THE WORLD WILL END. REALITY: (1) Not historical; Lucas invented for marketing. (2) 64-disc solution = 2^64 − 1 = 18,446,744,073,709,551,615 moves. (3) At 1 move/second = ~585 BILLION YEARS. (4) Universe currently ~14 billion years old; only 40× older than universe would need to pass. WORLD IS SAFE. Great teaching example of exponential growth + illustrating how small numbers become astronomical when doubled repeatedly. Also called Tower of Brahma or Lucas' Tower. Cultural: legend now permanent part of Hanoi lore.

Who invented the Tower of Hanoi?+

ÉDOUARD LUCAS — French mathematician (1842-1891). Invented + sold puzzle 1883 in Paris. Sold under PSEUDONYM 'N. CLAUS DE SIAM' (anagram of 'LUCAS D'AMIENS' — Lucas + his hometown). Marketing included fictional Brahma legend. Lucas also famous for: (1) LUCAS NUMBERS (mathematical sequence related to Fibonacci). (2) LUCAS-LEHMER PRIMALITY TEST for Mersenne primes. (3) MERSENNE prime testing algorithms still used today. Died tragically 1891 age 49 from erysipelas infection after fatal restaurant accident (broken plate cut his cheek). Tower of Hanoi remains his most famous popular invention.

Sources & provenance

Last verified 2026-08-25.verified