Three wooden pegs with coloured disks, the smallest disk flying to the peg with the flag, between Pip and Gus

Tower of Hanoi Race

Tower of Hanoi Race is the famous Tower of Hanoi puzzle for two players, and a race. You both get the same puzzle: three pegs and a tower of coloured disks, the biggest at the bottom. Move the whole tower to the peg with the flag, one disk at a time, without ever putting a bigger disk on a smaller one. Whoever finishes first wins. Choose 4, 5, 6 or 7 disks, and the classic tower or a mixed start. Play a friend on one phone, tablet or computer, or race the computer at four levels.

Computer level
Disks
Start
  • 2 players
  • 15-second to 8-minute races
  • Tap a peg to lift its top disk, then tap another peg, or drag the disk

How to play Tower of Hanoi Race

  1. The puzzle. There are three pegs on a board. In the classic start, every disk sits on the left peg, the biggest at the bottom and the smallest at the top, like a tower. Both players get the same puzzle (taking turns, the second player's is turned round, as explained below).
  2. Move one disk. Each move takes the top disk of one peg and puts it on another peg. Only the top disk of a peg can move.
  3. Never bigger on smaller. A disk can go on an empty peg or on a bigger disk, never on a smaller one. If you try, the disk shakes and stays in your hand, and you can put it somewhere else.
  4. The goal. Move the whole tower to the peg with the flag in your colour, biggest at the bottom, smallest at the top.
  5. The winner. The first player to finish wins. The counter shows how many moves each of you made and the fewest moves the puzzle can be done in, but only time counts. If you both finish at the same moment, to a hundredth of a second, the race is a draw.
  6. How many disks. With 4 disks the classic tower takes at least 15 moves, with 5 disks 31, with 6 disks 63 and with 7 disks 127. Every disk you add doubles the work, and one more.
  7. A mixed start. With Mixed, the disks start spread over the pegs at random, still never a bigger disk on a smaller one, and you gather them all on the flag peg. The game works out the fewest moves from that start and shows it next to your move count. Mixed starts are never nearly finished, and never longer than the classic tower.

Two players on one device

Before a race between two people, choose how you want to play:

  • At the same time. Each of you has your own tower. On a phone or a tall tablet they're one above the other, and the top one is turned round to face the player opposite, so you can play across a table. On a wider screen they sit side by side. With one keyboard, Orange uses A, S and D (or 1, 2 and 3) for the left, middle and right pegs, and Purple uses J, K and L.
  • Taking turns. One player moves the tower while the other looks away, then passes the device over. The second player gets the same tower the other way round: it starts on the right peg and goes to the left one, exactly as hard, but the moves they watched are no use as they were. With a mixed start the second player gets a different mixed start that is exactly as many moves from the finish, with the same disks to move in the same order. They have to beat the first player's time. The clock shows both times, and the race ends as soon as the second player finishes or runs past the time to beat.

Playing at the same time suits a touch screen. With one mouse, taking turns is better, and the game remembers which way you chose last time.

Controls

  • Tap a peg to lift its top disk, then tap the peg you want it on. Tap the same peg again to put it back. Anywhere in a peg's third of the board counts, so you don't have to hit the disk itself.
  • Drag a disk from one peg and let go over another.
  • Keyboard: press 1, 2 or 3 (or A, S, D) for the left, middle and right peg: the first press lifts the top disk and the second puts it down. The left and right arrow keys move a pointer between the pegs, Enter or Space presses the peg it points at, and Escape puts a lifted disk back.

Computer levels

Against the computer you both move the same tower at once, and its small board sits above yours (beside it on a wide screen), so you can watch every move it makes. It always knows the fewest moves from wherever its disks are. What makes it beatable is its pace, the pauses it takes to think (especially before a big disk moves) and its wrong moves: now and then it loses the thread and makes a move or two that don't help, which it then has to put right. Like a person, it has better and worse races.

These are the middle times we measured over thousands of races between computer players, with the classic tower of 4 and 5 disks:

  • Easy: slow, and often goes the wrong way for a few moves. About 1½ minutes and just over 3 minutes, and about 70 moves for 5 disks.
  • Medium: steadier, with the odd wrong move. About 35 seconds and 1¼ minutes.
  • Hard: quicker, and rarely goes wrong. About 26 and 53 seconds, and about 35 moves for 5 disks.
  • Expert: quick, and nearly always takes the shortest way. About 20 and 43 seconds.

Each extra disk roughly doubles these times: with 7 disks, Expert takes about 3 minutes and Easy about 14. We didn't measure how fast real people move disks, so the levels' speeds are our estimates: Expert is about the pace of a careful adult who knows the method, so a quick, practised player can beat it, and Easy is closer to a young child who is still finding the way.

Tips to win

  • Think about the biggest disk. To get the bottom disk onto the flag peg, every other disk has to be out of the way, all on the third peg. So the job is really: move the smaller tower to the middle, move the big disk across, then move the smaller tower on top of it.
  • The smallest disk moves every other move. In the shortest solution, every second move is the smallest disk, and from the classic tower it always goes the same way round the pegs. On the other moves there's only one move that doesn't touch the smallest disk, so you never have to choose.
  • Odd or even. From the classic tower, with 5 or 7 disks (an odd number), the smallest disk's first move goes straight to the flag peg, then to the middle, then back to the start, and so on round. With 4 or 6 disks it goes to the middle first, then to the flag peg, then back to the start. Get the first move wrong and you'll build the tower on the wrong peg.
  • Don't undo. Putting a disk straight back where it came from wastes two moves. If you're lost, look for the smallest disk and carry on round.
  • Use the count. "Best" shows the fewest moves. If your count is well over it at the end, you took a detour somewhere.
  • On a mixed start, look at the biggest disk first. If it's already on the flag peg, forget it and look at the next biggest. The first big disk that's in the wrong place tells you where all the smaller ones have to go.

Questions

What is the Tower of Hanoi?

The Tower of Hanoi is a puzzle with three pegs and a stack of disks of different sizes. The disks start as a tower on one peg, and the goal is to move the whole tower to another peg, one disk at a time, never putting a bigger disk on a smaller one. It's also called the Towers of Hanoi or the Tower of Brahma, and it's a favourite example in maths and computer science lessons.

Who invented the Tower of Hanoi?

The French mathematician Édouard Lucas brought it out in 1883, as a game found by a made-up "N. Claus (de Siam)", an anagram of "Lucas d'Amiens". Its booklet told a story of a temple in Benares where Brahmins move a tower of 64 golden disks, and the world will end when they finish. The story came with the puzzle, so it isn't an ancient legend, and many versions of it have been told since.

How many moves does the Tower of Hanoi take?

The fewest moves for a tower of n disks is 2 to the power n, minus 1: 7 moves for 3 disks, 15 for 4, 31 for 5, 63 for 6 and 127 for 7. The reason is the biggest disk. Before it can move, every smaller disk has to be stacked on the third peg, which is the same puzzle with one disk fewer. Then the biggest disk moves once, and the smaller tower has to be moved on top of it again. So each extra disk doubles the moves, plus one. The 64 disks of the story would take 18,446,744,073,709,551,615 moves: at one move a second, about 585 billion years.

What's the easiest way to solve it?

Move the smallest disk every other move, always the same way round the pegs, and in between make the only other move you can. With an odd number of disks the smallest disk goes first to the peg you want to finish on, and with an even number to the other one. From a tower on one peg, that gives the shortest solution every time, without having to think ahead.

Can young children play?

Yes. Choose 4 disks with the classic tower: it only takes 15 moves, and a mistake can always be put right. Race the Easy computer, which takes its time and often goes the wrong way. For a first go, try it alone a few times before racing.

Does the computer cheat?

No. There's nothing hidden in the Tower of Hanoi, and the computer moves its own copy of the same tower, one disk at a time, at its level's pace. You can watch every move it makes on its small board.

Updated 25 November 2026