GN Math logoGN Math
Tower of Hanoi

Tower of Hanoi

Tower of Hanoi is the old math puzzle with three pegs and a pile of rings sorted by size. The whole pile has to travel to the rightmost peg, and you carry only one ring per move.

This version by Douile draws everything on a dark canvas and runs straight in your browser. A counter compares your moves with the fewest possible, and a built-in solver can show you the perfect sequence.

How to play Tower of Hanoi

Pick up the top ring from any peg and set it on another. The ring you carry can rest on a bare peg or on top of a bigger ring, but a smaller ring underneath is off limits. While you hold a ring, it floats above the peg you have selected.

A new game has three rings and needs at least seven moves. Use the plus icon for a taller stack or minus for a shorter one, with three as the floor. Any change to the count resets the board.

The counter in the top corner reads your moves over the minimum, such as 11/7. When the full stack reaches the right peg, the view gives a quick zoom to mark the win. Press the play icon to watch the solver work, and the restart icon or R to begin again.

Controls

ActionKeyboardMouseTouch
Pick up or drop a ringSpace, Enter, Up/Down or W/SClick a pegTap a peg
Move between pegsLeft/Right or A/D——
RestartRRestart iconRestart icon
More or fewer rings—Plus or minus iconPlus or minus icon
Auto-solve—Play iconPlay icon

Tips

  • Check whether the ring count is odd or even. With an odd count, the smallest ring opens by moving to the right peg; with an even count, it goes to the middle.
  • In a perfect solution, the smallest ring moves on every other turn and always circles the pegs in the same direction.
  • On the turns in between, only one legal move exists that does not touch the smallest ring. Make that move.
  • Break big stacks into smaller jobs. To move five rings, first move the upper four onto the spare peg, shift the biggest, then rebuild the four on top.
  • Run the solver once on four or five rings. Seeing the rhythm makes it far easier to repeat on your own.

If you like Tower of Hanoi, try these

  • Fifteen Slide

    Minimal-move ordering puzzles pair well; slide numbered blocks through a single gap until they count up.

  • Peg Solitaire

    Planning a long sequence on pegs continues, jumping and removing them until only one is left.

Questions

What is the fewest moves for Tower of Hanoi?

The minimum is two to the power of the ring count, minus one. Three rings take 7 moves, four take 15 and five take 31, and the counter shows this target for you.

Can I play Tower of Hanoi with just the keyboard?

Yes. Left and Right (or A and D) choose a peg, while Space, Enter, Up, Down, W or S picks up and drops rings. R restarts.

Does it work on phones?

Yes. Tap the starting peg to grab a ring, then tap the destination peg to set it down. The canvas resizes to fit the screen.

More like this: all puzzle games · Math games · every game A–Z

More puzzle games

See all →
Light Switch Grid game screenLight Switch GridPuzzleLight Up Lamp Puzzle game screenLight Up Lamp PuzzlePuzzleLogic Mines game screenLogic MinesPuzzleLoopy Loop Puzzle game screenLoopy Loop PuzzlePuzzleMagnet Dominoes game screenMagnet DominoesPuzzleNet Pipe Puzzle game screenNet Pipe PuzzlePuzzleNetslide Pipe Puzzle game screenNetslide Pipe PuzzlePuzzleNumber Path game screenNumber PathPuzzlePearl Loop Puzzle game screenPearl Loop PuzzlePuzzlePeg Solitaire game screenPeg SolitairePuzzle