The 15-puzzle with two tiles swapped
Statement
The 15-puzzle has numbered tiles in a 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 and 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 be the number of inversions of the sequence of the tiles read row by row, and let be the row of the empty cell from the top. The parity of does not change under a move.
- Horizontal move. and are unchanged.
- Vertical move. changes by . The moved tile jumps over exactly other tiles, so changes by an odd number. Hence keeps its parity.
Conclusion. The solved position has and , so is even. The position with tiles swapped has and , so 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.