How does a sliding puzzle solver find the fewest moves? Say you finish a 3x3 sliding puzzle in 40 moves. On the board used below, a solver needs only 15. Below: how a solver thinks, in plain words and with no code, then three habits to copy by hand and four boards to try against the solver’s move counts. It’s about shortest solutions only. Want to simply finish a board? See how to solve a sliding tile puzzle.
1. What a sliding puzzle solver actually does
Does a sliding puzzle solver follow a method like row by row? No. It tries moves from the start board, keeps a list of the boards it has already met, and goes on until the solved board appears. Because it explores the shortest routes first, the first solution it finds is a fewest-moves solution.
The row-by-row method in how to solve a sliding tile puzzle is built for people and never gets lost. A solver gives up that safety to get the fewest moves.
The 3x3 board, also called the 8 puzzle, has 181,440 reachable boards. A computer can look at every one of them. A search of all of them finds that the hardest boards need 31 moves, and that exactly two boards need that many. Bigger boards are too large to check every one this way, so their solvers need cleverer shortcuts.
2. Count how far each tile is from home
For each numbered tile, count the squares it must travel, across and down, to reach its home square. Then add up all the counts. Solvers call this the Manhattan distance, like walking the blocks of a city. The blank isn’t counted.
Each move slides one tile one square, so the total changes by exactly one. That makes the total a lower bound: a board with a total of 13 can never be solved in fewer than 13 moves. Here’s a board to test it on:
The total is 13, and the real fewest is 15, two more. Why never 14? Each move changes the total by one, so a total of 13 means 13, 15, 17 or more moves. Of all 181,440 boards, the total equals the fewest moves exactly on 2,351 of them. On the rest, the fewest is higher.
3. Why the count is not enough: the best first move makes it worse
From the board above, the blank can move up, down or left. It sits on the right edge, so it can’t move right. Here are the three boards after those first moves, each with its total:
Blank up and blank down each give a total of 12, but each still needs 16 more moves, 17 in all. Moving the blank left raises the total to 14, and it still needs 14 more, 15 in all. Which first move wins? The one that makes the count worse.
A player who always takes the move that lowers the count loses two moves here. A solver doesn’t trust the count alone. It adds the moves already made to the count, and always carries on from the board with the smallest sum. A search method called A* works this way.
4. The fewest-moves solution to the worked board, move by move
The moves are the blank’s, as in the earlier guide: U, D, L or R. The shortest solution takes 15 moves: L L U R D R U L D D R U L D R. Three different 15-move solutions exist, and this is one. The row-by-row solution from the earlier guide takes 19: four more, but it never gets lost.
The total after each move is 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 for moves 1 to 15. After the first move it falls by exactly one on every move, so no detour is left. Four stages show it falling:
5. Three habits to copy from the solver
- Habit 1: count before you slide. Add up the distances to judge a board, and use the count to compare two options, not as an order to follow. On the worked board the count is 13, the least you can hope for, and the fewest is 15.
- Habit 2: never undo your last move. Sliding a tile straight back wastes two moves. The shortest solution never does it: no move in the solution above reverses the one before it.
- Habit 3: look ahead three or four moves, and allow a step that raises the count. The worked board shows this: its best first move raises the total from 13 to 14. Before you slide, trace the next three moves with your finger.
Do the habits guarantee the fewest? No, not by themselves, but they cut wasted moves.
6. Four boards to beat the solver
Each board must reach the goal 1 2 3 / 4 5 6 / 7 8 _, with the blank in the bottom-right corner. Moves are blank moves: U, D, L or R. All four boards are solvable. Try each one by hand, then open its answer to compare your move count with the solver’s.
Board A
Show the answer
8 moves: D L L U R R D D. It’s the only shortest solution, and here the count and the fewest are the same.
Board B
Show the answer
12 moves: L D D R U L U R D L D R. The count gives 8, which is only a lower bound here. It’s the only shortest solution.
Board C
Show the answer
17 moves: L U R D R U U L L D D R R U L D R. It’s one of three shortest solutions. The first move L is the winning one: it drops the total from 13 to 12. The move R also drops it to 12, but it leads to 19 moves in all.
Board D
Show the answer
31 moves: U U L D D R R U U L D L D R R U U L D L D R R U U L L D D R R. It’s one of 40 shortest solutions. Only two 3x3 boards need 31 moves, so 31 is the fewest for this board, and no one can beat it.
Within 5 moves of the fewest on boards A, B and C? That’s a good result.
7. Quick answers: can a human match a solver?
Can I find the fewest moves by hand?
Often, on the easier boards here. The three habits help, and patience does the rest. On a hard board like D you can find a long solution by hand, but you can’t know by hand that no shorter route exists.
Is the fewest-moves answer unique?
Not always. Boards A and B have one shortest solution each. Board C has 3. Board D has 40. The worked board has 3.
Do slide puzzle solvers use code?
Computer solvers are programs. Many use a search called A*, which relies on the count from section 2. You don’t need that to use the habits.
Shuffle a real board, count the distances, then try to beat your own best. For the full method, read how to solve a sliding tile puzzle, and for habits that carry over to other puzzles, read how to get better at logic puzzles.





