← Back to all games

Towers of Hanoi

Live · single-player study
Music
SFX
Your best—

The puzzle computer science students have been quietly resenting for decades, now available to resent on your lunch break too.

Towers of Hanoi was invented in 1883 by French mathematician Édouard Lucas, who packaged it as a toy puzzle but built it around a genuinely elegant piece of recursive logic — move a stack of discs from one peg to another, one at a time, never placing a larger disc on a smaller one. It's since become a staple of computer science education specifically because the optimal solution (2ⁿ − 1 moves for n discs) is one of the cleanest real-world examples of recursive thinking there is, which means most people's first encounter with it was a slightly resentful one in a first-year programming course. Outside the classroom it holds up as a pure logic puzzle: no luck, no clock pressure unless you want one, just the satisfaction of finding the shortest path.

How to play

Move the entire stack of discs from the first peg to the last, moving one disc at a time and never placing a larger disc on a smaller one. Choose your difficulty before starting.

Scoring

Scored on move efficiency — solving in fewer moves than the optimal solution isn't possible, but getting close to it scores best.

Tips for a higher score

  • The smallest disc moves every other move, and always in the same loop. With an odd number of discs it goes peg 1, 3, 2, 1, and so on. The other move in between is forced, so there is never a real choice to make.
  • The best possible run is 7 moves with 3 discs, 31 with 5 and 127 with 7. Your move count matters far more than your time, so slow down and plan.
  • To move a tower of discs, first move everything above the bottom disc out of the way, then move the bottom disc, then rebuild on top of it. The same trick works at every size.
  • The timer only starts on your first move, so take as long as you like to think before you click.

Why play this?

It looks like logic-puzzle homework, which means it's the single most defensible game on the site if questioned.

Questions

What's the difference between difficulties?

Easy, medium, and hard each use a different number of discs, with separate leaderboards for each.

What's the minimum number of moves?

The mathematical minimum is 2ⁿ − 1 moves for n discs — the game tracks how close you get.

What is the fewest moves possible?

It is 7 moves with 3 discs, 31 with 5 discs and 127 with 7 discs. Those are the best possible runs on Easy, Medium and Hard.

Does the timer run while I am thinking?

It starts on your first move, so you can think as long as you like before you begin. Your move count matters more than your time.

How do I move a disc?

Click a peg to pick up its top disc, then click the peg you want to move it to. You can never put a larger disc on top of a smaller one.

More games