Tower of Hanoi game

Move the Stack Without Breaking the Rule

Play the classic three-peg puzzle with clean controls, animated moves, hints, undo, and an auto-solver that reveals the shortest solution.

Board

Move all disks to peg C

No disk selected

Solver

Step-by-step shortest solution

The solver uses the classic recursive strategy: move the smaller stack aside, move the largest disk, then rebuild the smaller stack on top.

4 disks need 15 moves.

    How to play Tower of Hanoi

    The puzzle begins with all disks stacked on the left peg, largest on the bottom and smallest on top. Your goal is to move the full stack to the right peg.

    • Move only one disk at a time.
    • Only the top disk on a peg can move.
    • Never place a larger disk on top of a smaller disk.

    Minimum moves formula

    For n disks, the shortest solution always takes 2^n - 1 moves. That means 3 disks take 7 moves, 4 disks take 15 moves, and 8 disks take 255 moves.

    The challenge is not knowing the formula. The challenge is keeping the small disks out of the way while the largest disk moves at the right moment.

    Tower of Hanoi FAQ

    Why is it called Tower of Hanoi?

    The puzzle is commonly credited to French mathematician Edouard Lucas, who introduced it in the 19th century with a mythic story about a tower of disks.

    Can every Tower of Hanoi puzzle be solved?

    Yes. With three pegs and any number of disks, the puzzle can be solved by the same recursive method.

    What is the best first move?

    For an odd number of disks, move the smallest disk toward the target peg. For an even number of disks, move it toward the spare peg. The hint button handles this for you.

    Is Tower of Hanoi good for learning recursion?

    Yes. It is one of the clearest visual examples of recursion because solving n disks depends on solving the same problem for n - 1 disks.