Maths WorkshopMaths problems with full solutions
Exercise 1313Combinatorics › Counting principlesOlympiadAdded 5 Nov 2026

The 15-puzzle with two tiles swapped

#invariant#parity#inversions#puzzle

Statement

The 15-puzzle has 1515 numbered tiles in a 4×44\times4 frame with one empty cell; a move slides a tile into the empty cell. Starting from the solved position, can we reach the position in which tiles 1414 and 1515 are swapped and everything else is as before?

Hint

Read the tiles row by row, ignoring the empty cell, and count inversions. Find a quantity combining the number of inversions with the row of the empty cell that is preserved by every move.

Show solutionHide solution

Solution

Idea. Find an invariant that mixes the parity of inversions with the row of the blank.

Invariant. For a position, let NN be the number of inversions of the sequence of the 1515 tiles read row by row, and let r∈{1,2,3,4}r\in\{1,2,3,4\} be the row of the empty cell from the top. The parity of N+rN+r does not change under a move.
- Horizontal move. NN and rr are unchanged.
- Vertical move. rr changes by ±1\pm1. The moved tile jumps over exactly 33 other tiles, so NN changes by an odd number. Hence N+rN+r keeps its parity.

Conclusion. The solved position has N=0N=0 and r=4r=4, so N+rN+r is even. The position with tiles 14,1514,15 swapped has N=1N=1 and r=4r=4, so N+rN+r is odd. Since moves preserve the parity, this position cannot be reached. ∎

Remark. Sam Loyd's famous unsolvable puzzle. Exactly half of all positions are reachable.

Lesson. Parity of inversions is the invariant of sliding puzzles; correct it with the position of the blank.