4×4 sliding puzzle solution: a practical 15-puzzle method
Learn a layer-based 15-puzzle method, why row-ending pairs need planning, how to use local search, and how to finish without relying on a blind direction formula.
Updated 2026-11-13
A practical 4×4 method solves an outer row and column, then repeats on the smaller remaining rectangle. Treat the final pair of each row or column as a joint task; a direction formula only works when its starting arrangement matches.
Define the goal and the notation
The goal is ascending row order with the empty square at bottom right. A dot denotes that empty square. When a move names a tile, slide the named tile into the current gap. Do not mix this convention with instructions describing the direction in which the gap moves.
A solution method is a way to organise decisions across many starting boards. A fixed move sequence is only a tool for a particular local arrangement. Knowing this difference prevents the common mistake of repeating a memorised loop while the tiles are in the wrong starting positions.
Build the top row with room to manoeuvre
Bring the first tile to the top-left destination, then work toward the next position while leaving room for the remaining top-row tiles. Route the gap through unfinished cells. A move that temporarily takes a target sideways can be useful if it puts the gap on the required side for the next advance.
At the end of the row, plan the last pair together. Fixing the next-to-last tile too early can seal the route needed by the last one. Keep a small working rectangle below the pair, and arrange a legal sequence that inserts both in order. If your proposed sequence disturbs a protected tile, reconsider the setup before executing it.
A precise formula for one row-pair setup
The final top-row pair can enter from this arrangement:
1 2 . 3
5 6 7 4
9 10 11 8
13 14 15 12
Slide three left, then four up. The top row is complete and the gap is below its right edge. On this example, eight up followed by twelve up finishes the remaining column. Inspect the intermediate positions to confirm that every named tile shares an edge with the gap.
For a different scramble, prepare the same relationship before using the pair insertion: three in the top-right corner, four immediately below it, gap immediately left of three. Route the gap and targets through the unfinished area while protecting the completed left part of the row. Other lower tiles need not match the example. The starting relationship of the pair and gap is what makes the local formula legal and useful.
Use a concrete end-position example
Here is a nearly finished lower strip, with the upper rows already correct:
... upper rows already solved ...
9 10 11 12
. 13 14 15
Slide thirteen, fourteen and fifteen into the gap in that order. The empty square travels right, and the board finishes. Each move is legal because the next named tile is immediately beside the gap at that time.
This example is deliberately simple. It demonstrates how to read a sequence and protect the finished region. It is not a formula for arbitrary positions containing those tiles. If thirteen is elsewhere, the same sequence may be illegal from the very first move.
Complete the left column of the remainder
After the top row, solve the left side beneath it while using the remaining rectangle for gap movement. Again, keep the last vertical pair as a joint task. Then continue with the next outer row or column of the unfinished region.
The important invariant is the set of cells you preserve, not a requirement that every move improve the number of correct tiles. Some local rearrangements need temporary displacement within the working area. Keep completed outer layers protected unless you deliberately revise a recent pair setup.
Find a local sequence when you lack a formula
- Write the working rectangle, including the gap and target tiles.
- Mark cells outside it as protected.
- List legal gap moves that remain inside the working area.
- Explore short sequences, recording arrangements already visited.
- Stop when the target pair is correct and the gap has a usable exit.
Recording visited arrangements prevents endless back-and-forth exploration. For a small working area, this is a concrete way to discover a sequence instead of guessing. If no local route exists, expand the working area or release a prematurely fixed target. Do not conclude that the original puzzle is impossible merely because your temporary restrictions are too tight.
Finish and check parity if needed
The final small square can be solved by cycling its tiles around the gap when its arrangement belongs to the reachable cycle. A lone swapped pair is not repaired by endlessly repeating that rotation. For a manually assembled board, check the parity condition before spending a long session chasing an impossible swap.
For the standard even-width goal, the inversion count plus the gap's row counted from the bottom must be odd. Legal play preserves that condition. A solvable board cannot become unsolvable through legal moves, even if your current layer plan needs revision.
Where to play
YIGE / 一格华容道 has a 4×4 Medium route on HarmonyOS. Campaign hints provide a usable path, without promising the shortest solution on larger boards. Use them to study gap routing and pair setup, then practise the same planning idea on a different level.