Sliding Puzzle & Tower of Hanoi
The 15-puzzle at three sizes with a shortest-route solver, plus Tower of Hanoi with its optimal solution. Every puzzle is guaranteed solvable.
Things worth knowing
- Exactly half of all tile arrangements cannot be reached by sliding. Shuffling at random would therefore hand you an impossible puzzle about half the time, so this one shuffles by making real moves backwards from solved — every position it produces is guaranteed solvable.
- The classic 15-puzzle swindle of the 1880s offered a prize for swapping just the 14 and 15 back. It was safe money: that single swap flips the parity, putting the board in the unreachable half.
- Any solvable 3x3 can be done in at most 31 moves, and any 4x4 in at most 80. If you are well past that, you are going in circles rather than being unlucky.
- Work the top row and left column into place first and then never touch them again. Solving a sliding puzzle greedily, tile by tile in order, tends to undo itself.
- Tower of Hanoi has a fixed minimum of 2^n − 1 moves: 7 for three discs, 1,023 for ten. If you matched that, you played it perfectly — there is no better line to find.
- The Hanoi solution is the same shape at every size: move everything above the biggest disc out of the way, move the biggest disc once, then move the pile back on top of it.
How to use
- Pick the sliding tiles or Tower of Hanoi, and a size.
- Click a tile next to the gap to slide it, or click a peg to pick a disc up and another to put it down.
- Hint suggests one move; Solve it plays out the shortest route.
Frequently asked questions
Could I be given an impossible puzzle?
No, and that is worth explaining. Exactly half of all tile arrangements cannot be reached by sliding, so shuffling at random would hand you an impossible board about half the time. This shuffles by making real moves backwards from the solved state instead, so every position it produces is reachable by construction.
What was the 14-15 puzzle swindle?
In the 1880s Sam Loyd offered a large prize for swapping just the 14 and 15 back into order. It was safe money: that single swap flips the parity of the board, putting it in the unreachable half. Nobody could ever have claimed it.
How many moves should it take?
Any solvable 3x3 can be done in at most 31 moves and any 4x4 in at most 80. If you are well past that you are going in circles rather than being unlucky.
Why will it not always solve a 4x4 or 5x5?
Finding the guaranteed SHORTEST route grows explosively with size, and a browser tab that freezes for a minute is worse than an honest answer. Past a search budget it says so and offers Hint instead, which gives one good move at a time.
Is there a strategy for the sliding puzzle?
Solve the top row and left column first, then never disturb them again. Working strictly tile by tile in numerical order tends to undo your own progress, which is why it feels like it fights back.
What is the fewest moves for Tower of Hanoi?
Exactly 2^n − 1: seven moves for three discs, 1,023 for ten. If you matched that number you played it perfectly, and there is no better line to find — worth knowing, because people often assume they did badly.
Is there a pattern to Hanoi?
Yes, and it is the same at every size: move everything above the biggest disc out of the way, move the biggest disc once, then move that pile back on top of it. The solution is that rule applied to itself all the way down.
🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.