The rules, why some positions can never be solved, and a method that solves every grid
The sliding puzzle is a square frame of numbered tiles with one space left empty. The 4×4 version, with tiles 1 to 15, is the famous 15-puzzle. It is usually credited to Noyes Chapman, a postmaster in New York State, in the 1870s, and in early 1880 it became a full-blown craze across the United States and then Europe. Years later the puzzle writer Sam Loyd falsely claimed to have invented it, and told of offering $1,000 to anyone who could solve a version with the 14 and 15 swapped. That prize would have been safe: the position cannot be solved at all.
PlayVersusAI offers three sizes and scores you on the number of slides you need. There is no hidden information and no luck once the board is dealt: a methodical solver can finish any position, and a skilful one does it in far fewer moves.
For a new scramble, click any size button above the board, including the selected one.
Write the tiles out in reading order, skipping the gap, and count the inversions: pairs where a larger number comes before a smaller one. The solved puzzle has zero. A sideways slide does not change the reading order at all. On a grid with an odd width, like the 3×3 and 5×5, a vertical slide moves one tile past an even number of others (two or four), so the inversion count always changes by an even amount. The count can never switch between odd and even, so an arrangement with an odd number of inversions can never be solved.
On the 4×4, a vertical slide moves a tile past three others, which does flip the parity, but it also moves the gap up or down a row. What is preserved is the parity of the inversion count plus the gap's row. Loyd's 14-15 position has one inversion with the gap in its home corner, so it is out of reach. In 1879 the mathematicians William Johnson and William Story published a proof that exactly half of all arrangements can be reached. That is 181,440 positions on the 3×3 and over ten trillion on the 4×4.
That is why our boards are never dealt by placing tiles at random. Each one starts solved and is scrambled with 200 random legal slides per cell, so it can always be undone.
Think in terms of the gap. To push a tile one square, bring the gap to the square in front of it without disturbing solved tiles, then slide the tile in. Pushing it another square the same way costs five moves: four to bring the gap around and one to slide. Alternating directions to move diagonally costs only three per step, so route tiles along diagonals where you can.
Place 1 and 2 directly. The last two tiles of the row must go in as a pair, because putting the 3 in its spot first leaves no way to get the 4 past it. On the 4×4: move the 3 into the top-right corner and the 4 to the square directly beneath it. Steer the gap to the square left of the 3, slide the 3 left, then slide the 4 up. If the 4 gets stuck beside the 3 in the top row, don't try to swap them in place. Move the 4 at least two rows down, then bring it back up underneath the 3.
Once the top row is done, never move those tiles again. Repeat the method for the second row (5, 6, then 7 and 8 as a pair), which leaves only the bottom two rows.
The pair trick fails if you try to finish the last two rows row by row, because there is no spare row to work in. Turn the problem sideways and solve one column at a time from the left. On the 4×4, the first column needs 9 above 13. Put the 9 in the bottom-left corner, the 13 directly to its right and the gap above the 9. Slide the 9 up, then slide the 13 left, and the column is finished. Do the same for 10 and 14 in the second column.
That leaves three tiles (11, 12 and 15) and the gap in a 2×2 square. Cycle them around the square in one direction until they line up. Because every puzzle here is solvable, they always fall into place within a few rotations.
On the 3×3, solve 1, then 2 and 3 as a pair (2 in the corner, 3 beneath it). Next, solve the left column by putting 4 in the bottom-left corner, 7 beside it and the gap above the 4, then sliding the 4 up and the 7 left. Finally, rotate 5, 6 and 8 home. On the 5×5, solve the top three rows one at a time, pairing 4 and 5, 9 and 10, then 14 and 15. Then work through the bottom two rows column by column (16 over 21, 17 over 22, 18 over 23) and finish with the 2×2 of 19, 20 and 24.
The method always works, but it isn't efficient. Computer searches have shown that every 3×3 position can be solved in 31 moves or fewer and every 4×4 in 80 or fewer, while a row-by-row solve typically uses far more. To close the gap, plan the gap's route before clicking, avoid moving it back and forth, and nudge the next tile closer while placing the current one.
Difficulty is the grid size; the rules and scrambling method never change.
| Difficulty | What changes |
|---|---|
| Easy | 3×3 with 8 tiles, scrambled with 1,800 random slides. Only one row needs solving before the final column and 2×2, and no position needs more than 31 moves. |
| Medium | The classic 4×4 15-puzzle, scrambled with 3,200 random slides. You solve two full rows, then two column pairs, then the 2×2. This is the size the page opens with. |
| Hard | 5×5 with 24 tiles, scrambled with 5,000 random slides. You solve three full rows before the bottom two, so routing the gap efficiently matters far more. |
Free to play - no account needed