This is a finished 15 puzzle with only the 14 and 15 tiles swapped. It looks “almost done,” but this board can never be completed, no matter how you move the tiles.

123456789101112131514

Sliding puzzle arrangements split exactly in half: “solvable arrangements” and “unsolvable arrangements.” You can tell which is which just by counting one number.

Counting inversions

Leaving out the empty space, read the tiles from the top left to the right, one row at a time. As you go, count the pairs where a larger number comes before a smaller number. This count is called the number of inversions.

For example, reading the 3×3 board below gives 3, 1, 2, 4, 5, 7, 8, 6.

31245786

The pairs with the larger number first are (3,1), (3,2), (7,6), and (8,6): four pairs, so there are 4 inversions. On a finished board, every tile is in ascending order, so there are 0 inversions.

On a 3×3, an even number of inversions means solvable

On boards with an odd number of columns (3×3, 5×5, 7×7), the rule is:

  • if the number of inversions is even, it can be solved
  • if the number of inversions is odd, it cannot be solved

The board above has 4 inversions (even), so it can be solved (16 moves at minimum).

31245786
Inversions 4 → solvable
12345687
Inversions 1 → unsolvable

Why even and odd never change

  • When you slide a tile sideways, the reading order does not change. The number of inversions stays the same.
  • When you slide a tile up or down, that tile jumps over two other tiles in the reading order (on a 3×3). Depending on how it compares with those two tiles, the number of inversions goes up by 2, goes down by 2, or stays the same.

Either way, whether the number of inversions is even or odd never changes. A finished board has 0 (even), so from a board with an odd number of inversions, no amount of moving will ever get you to the finished board.

On a 4×4, count “the empty space’s row” too

On boards with an even number of columns (4×4, 6×6), sliding a tile up or down makes it jump over three tiles (on a 4×4), so the number of inversions switches between even and odd. In exchange, every vertical slide also moves the empty space’s row by one.

So you tell them apart with this total:

inversions + the number of rows below the empty space

  • If this total is even, it can be solved
  • If it is odd, it cannot be solved
123456789101112131514
14 and 15 swapped Inversions 1 + rows below the gap 0 → unsolvable
123456789101112131415
Empty space moved to the top left Inversions 0 + rows below the gap 3 → unsolvable

The board with 14 and 15 swapped has 1 inversion, and the empty space is in the bottom row, so the total is 1 (odd). That is why it cannot be solved.

The board with the empty space moved to the top left has every tile in ascending order and 0 inversions, but there are 3 rows below the empty space, so the total is 3 (odd). This one cannot be solved either.

151413121110987654321
Descending (empty at bottom right) Inversions 105 + rows below the gap 0 → unsolvable
151413121110987654321
Descending (empty at top left) Inversions 105 + rows below the gap 3 → solvable

A board with the tiles in descending order has 105 inversions. With the empty space at the bottom right, the total is 105 and it cannot be solved, but with the empty space at the top left, the total is 108 and it can.

Exactly half

In 1879, the American mathematicians Johnson and Story used this idea of even and odd to show that unsolvable arrangements exist, and that every arrangement on the solvable side can always be solved.

Swapping two tiles switches the number of inversions between even and odd. Because of that, all arrangements split exactly in half into “solvable arrangements” and “unsolvable arrangements.” On a 4×4 there are about 20.9 trillion arrangements in all, and about 10.5 trillion of them are solvable (How many arrangements are there?).

Even on the smallest board, a 2×2, only 12 of the 24 ways to arrange three tiles and the empty space can be reached by sliding.

How to tell whether your board can be solved

  • If you took the tiles out of the frame and rearranged them, count the inversions (and on a 4×4, the empty space’s row too).
  • If it turns out to be unsolvable, swap any two tiles other than the empty space, and it becomes solvable (Making a sliding puzzle at home).
  • A board scrambled by sliding can always be put back, so it can always be solved.

The app “Slide Puzzle” checks even and odd after mixing the tiles, and if the arrangement is unsolvable, it swaps two tiles before showing it, so every puzzle can be solved (How solvable puzzles are made).

This even-and-odd story is also known from the 19th-century tale of a prize for “the board with 14 and 15 swapped” (Sam Loyd’s 14-15 puzzle).