A reliable method for solving sliding puzzles
Almost everyone solves a sliding puzzle the same way at first: chase whichever tile looks closest to where it belongs, get eleven of them into position, and then discover that fixing the last few requires pulling the first few apart. That loop can run for a long time. The puzzle is not hard — it is unforgiving of a bad order, because every tile you move drags its neighbors around with it.
The method below fixes the order. It is slower than a lucky run and it is not the shortest possible solution, but it finishes every time, it scales from a three-by-three to a five-by-five without changing, and it never asks you to undo work you have already done.
The finished picture, and what the board tracks
The goal is the tiles in reading order with the gap in the bottom-right corner. On a four-by-four:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 _
Our sliding puzzle offers three sizes —
three-by-three, four-by-four and five-by-five — with the four-by-four selected by
default and your last choice remembered. It counts your moves, and the clock does not start until your
first move, so opening the page and walking away costs nothing. Best move count and best time are kept
separately for each size and lower always wins, which matters: a record on the three-by-three
cannot be spoiled by a slow five-by-five. Those records live in your own browser under keys beginning
with bg: and nowhere else.
Solve in layers, not all at once
The central idea is to shrink the puzzle. Finish the top row completely, then finish the left column completely, and what remains is a smaller sliding puzzle in the bottom-right corner that you solve the same way. On a four-by-four that leaves a three-by-three; solve its top row and left column and you are down to a two-by-two.
step 1: top row step 2: left column what is left A A A A A A A A A A A A . . . . B . . . B ? ? ? . . . . B . . . B ? ? ? . . . . B . . . B ? ? ? A = finished and never touched again B = finished second ? = a 3x3 puzzle, solved by the same two steps
Two rules make the layers hold. First, work within the unfinished region only: once the top row is done, the gap should stay in rows two and below, and your route from one tile to another should never pass through a finished square. Second, place tiles in order along the line you are building — leftmost first for a row, topmost first for a column — because a tile placed out of order is a tile you will have to move again.
Moving a single tile toward its destination is the one bit of hand skill involved, and it is easier than it looks. To move a tile one square left, bring the gap to the square left of it and slide. The work is all in walking the gap around the tile without pushing the tile backwards, which means going around it rather than through it. On a phone this is the moment to slow down; most wasted moves come from swiping in a rhythm instead of looking at where the gap is.
The last tile of a row is the only real trick
The first tiles of a row go in easily. The last one does not, and this is where unstructured play collapses: the final tile of the top row can only enter its corner square from below or from the side, and whichever direction you choose seems to push a finished tile out of the way.
The solution is to build the end of the row somewhere else and rotate it in. On a four-by-four, with tiles 1 and 2 already placed, do not aim tile 3 at its own square. Instead:
- Put tile 3 in the top-right corner — the square where tile 4 belongs.
- Put tile 4 directly below it, in the second row.
- Bring the gap to the square one place left of that corner.
set it up slide 3 left bring 4 up 1 2 _ 3 1 2 3 _ 1 2 3 4 . . . 4 . . . 4 . . . _ . . . . . . . . . . . . . . . . . . . . . . . .
Two moves close the row, and neither of them goes anywhere near tiles 1 and 2. The same maneuver handles the left column, rotated ninety degrees: park the second-to-last tile of the column in the bottom square of the column, park the last tile to its right, bring the gap above, and slide them home.
Notice what makes it work. You are not solving the last two tiles individually; you are placing them in a shape that a short rotation converts into the answer. That is the general pattern in this puzzle, and it has a name.
The three-tile rotation
Take any two-by-two block of squares with the gap in one of them and walk the gap around the block — four moves, returning it to where it started. The three tiles have each shifted one position around the loop, and nothing outside the block has moved at all.
before after four moves _ b _ c d c b d the gap is home again; b, c and d have each moved one step
This is the whole toolkit. Every placement in the layered method is really a series of these rotations, and the useful consequence is that three tiles can be cycled without disturbing anything else. When two tiles in an unfinished region are swapped and you cannot see how to fix them, look for a third tile to bring into the loop; a two-tile swap is impossible on its own, and a three-tile cycle is four moves.
It is also how the puzzle ends. When the layers have reduced you to a two-by-two block in the bottom-right corner, there is nothing left to plan: rotate the block. At most two full rotations put the three tiles in place, and if a solvable board has been solved correctly up to that point, it always lands.
Why forcing the last tile is the mistake that restarts you
The single most expensive habit in this puzzle is refusing to set up the rotation, and instead pushing the last tile of a row directly at its square. It works, in the sense that the tile arrives — and it arrives by pulling the tile beside it out of position, so the row is now finished except that it is not. Repair the neighbor and the corner tile leaves again.
That is the loop people describe as being stuck on the last few tiles, and it is not bad luck. It is a structural fact: the final square of a line cannot be filled without moving through the line, unless you arrive by the rotation. Twenty extra moves spent setting the rotation up will always beat five minutes of trying to force it.
A related error is worth naming. When something goes wrong late, the temptation is to shuffle the bottom rows freely, hoping to stumble into the right arrangement. Don't. Go back to the layer you were building, identify which two tiles are in each other's places, and cycle three of them deliberately. The puzzle is small enough to reason about and large enough to punish guessing.
The parity fact behind every fair shuffle
Here is the part of this puzzle that is genuine mathematics rather than technique. Sliding moves cannot reach every arrangement of the tiles. Exactly half of all possible arrangements of a four-by-four are unreachable from the solved state, and therefore unsolvable — no sequence of legal moves, however long, gets them home.
The reason is that each slide changes two things in lockstep: it swaps the gap with one tile, and it moves the gap one square. Track the number of pairs of tiles that are out of order along with the gap's distance from its home corner, and the combination of the two never changes its odd-or-even character. A solved board has that quantity even. Swap any two tiles and it becomes odd, and nothing you do at the board can change it back.
The concrete version is the famous one: take a solved four-by-four, lift out the last two numbered tiles and exchange them. That board looks one move from finished and it cannot be solved at all.
Which is why a generator must not shuffle the tiles the way you shuffle a deck of cards. Ours begins at the finished board and walks away from it through several hundred legal slides — 308 on the three-by-three, 392 on the four-by-four, 500 on the five-by-five — choosing randomly among the slides available at each step and declining to immediately reverse the move it just made, so the walk keeps travelling instead of wobbling in place. In the rare event that the sequence lands back on the solved arrangement, it keeps making legal moves until it does not. Every board you are dealt here has a solution, because every board was built by taking one apart.
What is exact and what is not. The shuffle lengths above (308, 392, 500) and the parity result are facts about the code and the mathematics, not measurements. The following are estimates, drawn from boards we solved ourselves and nothing more: with this method we finish a three-by-three in roughly 40 to 80 moves and under a minute, a four-by-four in roughly 150 to 250 moves and three to six minutes, and a five-by-five in the region of 400 to 600 moves and ten to twenty minutes. The method is not designed to be move-efficient — it trades extra moves for never getting stuck — so treat your own previous best on the same size as the only meaningful benchmark.
Playing it on this page
You can move a tile three ways, and they suit different situations. Clicking or tapping a tile slides it if it is next to the gap, which is the precise option when you are placing a specific tile. The arrow keys and W, A, S and D pull in the tile from that side of the gap, which is faster when you are walking the gap a long way. On a touchscreen you can swipe the board, and the tile that moves is the one your swipe pushes toward the gap.
Two smaller details are worth knowing. Tiles that are sitting in their final position are marked on the board, so your finished layers are visible at a glance rather than something you have to verify by reading numbers. And there is a guide toggle that adds each tile's home row and column to its label and tooltip — useful on the five-by-five, where working out from memory that tile 18 belongs at row four, column three is a small tax you do not need to pay while you are learning the method.
A practice order that works
- Solve three-by-threes until the top row plus left column routine is automatic. It is the same routine you will use on the larger boards, with less to keep track of.
- Move to the four-by-four and solve the top row only, then deliberately look at where the gap is before continuing. This is the habit that prevents accidental damage to a finished layer.
- Do five four-by-fours without watching the move counter. Speed comes from not repairing things, not from moving quickly.
- Then try the five-by-five once. It takes three or four times as long and teaches nothing new, which is a good sign: it means the method is doing the work rather than your memory.
Questions players ask
What order should I solve the tiles in?
The whole top row, then the whole left column, then repeat on the smaller region that is left. Stop when a two-by-two block remains and rotate it.
How do I finish a row without breaking it?
Park the second-to-last tile in the corner square where the last tile belongs, park the last tile directly below it, bring the gap alongside, and slide them in. Two moves, and the rest of the row is untouched.
Can a board here be impossible?
No. Half of all arrangements are unsolvable in general, but every board on this page is produced by making legal moves from the solved state, so it can always be reversed.
Which sizes can I play?
Three-by-three, four-by-four and five-by-five. Your choice is remembered, and best moves and best time are stored per size.
Is this method the shortest solution?
No, and it is not trying to be. It trades extra moves for a guarantee that you never have to dismantle finished work. Optimizing move count is a different pursuit from finishing reliably.
Are my best times sent anywhere?
No. They stay in this browser's local storage under keys beginning with bg:. Wipe
your browsing data and the records go with it.