Experimental

Tower of Hanoi Solver

Solve the Tower of Hanoi puzzle for any number of disks, listing the optimal move sequence and confirming the minimum number of moves.

Last reviewed by the Radiatus Cloud team

Solve the Tower of Hanoi puzzle with the optimal move sequence.

Need this done properly for your business?

Radiatus delivers secure cloud, DevOps & compliance engineering.

Book a free consult

Solve the Tower of Hanoi

The Tower of Hanoi is a classic puzzle with three pegs and a stack of disks of different sizes, where the goal is to move the whole stack from one peg to another, moving one disk at a time and never placing a larger disk on a smaller one. This solver generates the complete optimal sequence of moves for any number of disks and confirms the minimum move count, which is always two to the power of the number of disks, minus one. Three disks require seven moves.

The solution uses the elegant recursive strategy that makes the puzzle a staple of computer science teaching.

Recursion made visible

The Tower of Hanoi is the textbook example of recursion: to move n disks, you move the top n minus one disks aside, move the largest disk, then move the stack back on top. This simple idea generates the entire optimal solution and explains why the move count doubles with each extra disk. The puzzle also has a famous legend about monks moving sixty-four golden disks, which would take longer than the age of the universe.

Because the number of moves grows exponentially, the tool caps the disk count to keep the output manageable. All calculation happens locally in your browser.

Related tools

Frequently Asked Questions

What are the rules of the Tower of Hanoi?

Move the whole stack to another peg, one disk at a time, never placing a larger disk on top of a smaller one.

What is the minimum number of moves?

Two to the power of the number of disks, minus one, so three disks need seven moves and ten disks need one thousand and twenty-three.

Why is it used to teach recursion?

Its optimal solution is naturally recursive: move the smaller stack aside, move the largest disk, then move the stack back, repeating the idea.

Why limit the number of disks?

The number of moves doubles with each disk, so large counts produce enormous lists. The tool caps the disks to stay practical.

Privacy & Security

Everything runs in your browser; nothing is uploaded.

Data: None
Client-side-Side
Active
v1.0

How to Use

Enter the number of disks to generate the solution.

Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.