Tower of Hanoi Online
Move the whole tower to another peg, one disk at a time, without ever putting a bigger disk on a smaller one. Pick from 3 to 8 disks.
Drag the disks, or tap one peg and then another. The 1, 2 and 3 keys work too.
How to play the Tower of Hanoi
All the disks start stacked on the first peg, from the biggest (at the bottom) to the smallest (on top). The goal is to move the whole tower to peg 2 or peg 3.
You can only move one disk at a time, always the top disk of a stack, and you can never put a bigger disk on a smaller one. Drag a disk to another peg, or tap the peg it’s on and then the peg you want. On a keyboard, use the 1, 2 and 3 keys.
The counter shows how many moves you’ve made and the minimum possible (2 to the power of the number of disks, minus 1). If you get stuck, the “Show solution” button finishes the puzzle for you, showing the shortest path from where you are.
Frequently asked questions
What’s the minimum number of moves for the Tower of Hanoi?
With n disks, the minimum is 2ⁿ − 1: 7 moves with 3 disks, 15 with 4, 31 with 5, 63 with 6, 127 with 7 and 255 with 8.
Is there a trick to solving the Tower of Hanoi?
Yes. Always move the smallest disk in the same direction, in a cycle (1 → 2 → 3 → 1 if the number of disks is even; 1 → 3 → 2 → 1 if it’s odd). On the next move, make the only legal move that doesn’t involve the smallest disk. Repeat until you’re done.
What is the Tower of Hanoi good for?
It’s a classic puzzle invented by French mathematician Édouard Lucas in 1883. Schools use it a lot to build logical thinking and planning skills, and it’s a go-to example for teaching recursion in programming.