Main Page | See live article | Alphabetical index

N-puzzle

The n-puzzle is known by many names, including the 8 puzzle, the 15 puzzle, and various other names. It is a sliding block puzzle that consists of a grid of numbered squares with one square missing, and the labels on the squares jumbled up. If the grid is 3x3, the puzzle is called the 8-puzzle or 9-puzzle. If the grid is 4x4, the puzzle is called the 15-puzzle or 16-puzzle. The goal of the puzzle is to un-jumble the squares by only making moves which slide squares into the empty space, in turn revealing another empty space in the position of the moved piece.

The n-puzzle is a classical problem for modelling algorithms involving heuristics. Commonly used heuristics for this problem include counting the number of misplaced tiles and finding the sum of the Manhattan distances between each block and its position in the goal configuration. Note that both are admissible.

It is possible to use parity arguments to show that some starting positions for the n-puzzle are impossible to resolve, no matter how many moves are made. This is done by considering a function of the tile configuration that is unchanged by making any valid move, and then using this to partition the space of all possible labelled states into equivalence classes of reachable and unreachable states.

How Sam Loyd made his fortune

In its most famous version, the fifteen puzzle is a game in which 15 of the 16 squares of a 4x4 frame are filled with numbered sliding pieces, leaving one space in which to slide one piece at a time. The object is to slide the 15 pieces into numerical order.

Thus, the goal is to produce this configuration:

If the pieces 14 and 15 are exchanged, resulting in the following initial configuration:
then the puzzle is not soluble.

The 'hook' in the fifteen puzzle is that there are two distinct sets of positions which can be assembled from the pieces, depending on the parity (the parity in this context is the number of pairs of pieces that must be swapped to obtain the solution), and there is no way of moving between them using the allowed moves, as they preserve parity.

This allowed Sam Loyd, who invented the puzzle in the 1870s, to offer a prize of $1000 which could never be claimed, fuelling the popularity of the game. The game became a craze in both the USA and in Europe.

For larger versions of the fifteen puzzle, the problem of finding a solution is easy. The problem of finding the shortest solution is NP-hard.

External links