⭐ Starlight Tools / Towers of Hanoi

Towers of Hanoi — Calm, Visual, & Learnable

Moves0 Optimal0 Disks3
Tap a peg to pick up the top disk, then tap another peg to place it.
Choose a peg to pick up a disk. Only smaller disks can sit on larger ones.

Everything runs locally in your browser — no uploads, no accounts.

About Towers of Hanoi

This calm version lets you learn by doing. Play manually with simple tap/tap moves, or watch the Auto-Solve animate the optimal solution. You can adjust the number of disks and the animation speed at any time.

  • Goal: Move the full stack from Peg A to Peg C.
  • Rule: Only the top disk can move, and a larger disk can never sit on a smaller one.
  • Optimal moves: For n disks, the best is 2^n − 1 moves.

FAQ

Why can’t I place this disk? You’re trying to place a larger disk on a smaller one. Try another peg.

Can I change disks mid-game? Yes — use New and the slider. It resets the board gently.

What does Auto-Solve do? It computes the optimal move list and animates each move at the speed you choose.

Towers of Hanoi — Concept, Strategy, and Optimal 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.

Optimal Number of Moves

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.

Why Teachers and Students Use It

  • Recursion: See a smaller copy of the same task inside the bigger task.
  • Proof by induction: Natural fit for showing correctness and minimality.
  • Complexity awareness: Time grows as O(2^n), highlighting exponential growth.
  • Calm practice: A gentle, rule-based environment for focus and patience.

Beginner Strategy (Works Every Time)

  1. Always move the smallest disk in a repeating pattern (its position alternates every other move).
  2. When not moving the smallest disk, you have only one legal move—make it.
  3. Keep attention on the destination peg: you’re building the final stack from largest at the bottom to smallest on top.

Manual Play vs Auto-Solve

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.

Common Questions

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.