Moves
0
Minimum
15
Fewest from here
15
Time
0:00

Tower of Hanoi Solver

Stuck halfway through? Press Solve from here and watch the shortest possible solution, starting from the exact position on the board.

How to use the solver

  1. Choose the number of disks, from 3 to 10.
  2. Play a few moves, or press Shuffle for a random position.
  3. Press Solve from here. The board now shows the solver’s moves, and the counter tells you how many are left.
  4. Use Play and Pause, Previous move and Next move, or the Speed menu. Start over replays the solution; Back to my game returns to your own moves exactly as you left them.

It solves any position, not only the start

Most online solvers only know how to carry a full tower from one peg to another. This one starts from whatever is on the board, including the messy positions you reach after a wrong turn, and always gives the fewest moves possible from there.

Is the answer really the shortest?

Yes. With three pegs the solver follows a rule that is provably optimal (below), and we checked it against a brute-force search of every possible position for up to seven disks and each target peg; it matched the true shortest distance every time. With four pegs there is no such short rule for an arbitrary position, so the page searches every position of the size you picked (a million of them for ten disks) and walks the shortest route: the answer is exact by construction.

How the solver thinks

Look at the largest disk that is not where it should be. All the smaller disks must first be stacked on the third peg, out of its way; then the large disk moves once; then the smaller disks are carried back on top of it. The same idea applies to the smaller disks, one size at a time. The full explanation, with a worked example, is in how to solve the Tower of Hanoi, and the move counts are derived on the formula page.

Questions

Does it work with four pegs?
Yes. Choose 4 pegs under the board. With a spare peg the puzzle is called Reve’s puzzle and needs far fewer moves: 9 for four disks instead of 15, 49 for ten instead of 1,023.
Does a game finished by the solver count as my best score?
No. Games the solver finishes, and games that start from a shuffled position, never change your records. Your own best moves and times are kept on this device only.
How many moves does 10 disks take?
From the classic start, 1,023, which is 210 − 1. From any other position it can be fewer; the board shows the exact number under “Fewest from here”.
Can I use it on a phone?
Yes. Tap a peg and then the peg you want to move to, or drag the top disk.