Tower of Hanoi

Move the whole stack to the right peg, one disk at a time, never a big disk on a small one.

Difficulty
Difficulty: Medium
Play time
4 min
Moves
0
Par
15
Best
–

Pick a number of disks and press Start.

Tap a peg to lift, tap another to drop. Keys 1, 2, 3 pick pegs.

How to play

  1. Pick how many disks to play with, from 3 to 7, and press Start.
  2. Tap a peg to lift its top disk, then tap another peg to drop it there. Keys 1, 2 and 3 work too.
  3. A disk may only go on an empty peg or on a larger disk. Tap the same peg again to put a disk back.
  4. Get the whole stack onto the right peg. The fewest possible moves are shown as par.

About this game

The Tower of Hanoi is a mathematical puzzle from the nineteenth century. You start with a stack of disks on the left peg, the largest at the bottom and the smallest at the top. The goal is to rebuild the same stack on the right peg. You may move only one disk at a time, only the top disk of a peg, and never place a disk on top of a smaller one.

With three disks the puzzle takes seven moves at best, and every extra disk roughly doubles the work: four disks need fifteen moves, five need thirty-one, and seven need one hundred and twenty-seven. In general n disks need two to the power of n, minus one, moves. That number is shown as par, and finishing in exactly par moves is a perfect solve.

The puzzle has a neat recursive solution. To move a stack of n disks, first move the n − 1 disks above the largest one out of the way to the spare peg, then move the largest disk, then move the n − 1 disks back on top of it. A simple pattern follows from this: the smallest disk moves on every other turn, always around the pegs in the same direction.

Use Undo to take back moves while you explore, or Restart to begin the same size again. Your fewest moves for each number of disks is saved in this browser, so you can try to bring a five or seven disk solve all the way down to par.

What this does not measure

This is a puzzle for fun. It is not an IQ test or a measure of planning or memory, and needing more moves than par says nothing about how your mind works.

Your best score is saved in this browser only.

More games to try