4×4
6

More information about the 15 Puzzle

15 Puzzle

Fifteen numbered tiles and one gap in a 4×4 tray. Slide them back into order, 1 to 15, with the gap in the last corner. Every position Shuffle makes can be solved, but half of all arrangements cannot, and the most famous of those is Sam Loyd's 14-15. Click a tile next to the gap to slide it in, or a tile further along the gap's row or column to slide the whole line. Put the tiles back in order with the gap in the bottom right corner. Shuffle mixes them, and Solve finds a way and plays it move by move.

How it works

  1. Click a tile next to the gap to slide it in, or a tile further along the same row or column to slide the whole line.
  2. Put the tiles back in order from 1 in the top left corner, with the gap in the bottom right corner.
  3. Stuck? Press Solve to watch it finish, or Step for one move at a time, then save a PNG.

How to play

Only a tile next to the gap can move, and it moves into the gap. Click a tile further along the gap's row or column and every tile in between slides with it; the arrow keys slide the tile on that side of the gap. Moves counts every tile that moves, and Undo takes back a slide. Size switches between the 8 puzzle on 3×3, the 15 puzzle, and the 24 puzzle on 5×5.

Half of all positions cannot be solved

Lift two tiles out, swap them, and the puzzle can never be solved again. Every slide swaps the gap with a tile, and the gap needs an even number of slides to get back to its corner, so the tiles can only be rearranged by an even number of swaps. A single swap is odd. Of the 20,922,789,888,000 ways to fill the 16 squares, exactly half can be reached. Loyd's 14-15 starts in the other half.

How Solve works

Solve searches for a way back with A*, guided by how far each tile is from its home square, plus two extra moves for every pair of tiles that sit in their own row or column in the wrong order. On the 3×3 board it finds the shortest solution, which is never more than 31 moves. On larger boards it settles for a short solution found at once instead of the shortest one, which can take a long search: the hardest 4×4 positions need 80 moves.

Frequently asked questions

Can every 15 puzzle be solved?

Only half of all arrangements. On the 4×4 board a position can be solved when the number of tile pairs in the wrong order, plus the row of the gap counted from the bottom, is odd. Shuffle only makes positions that can be solved.

What is Sam Loyd's 14-15 puzzle?

The solved order with 14 and 15 swapped. Loyd told of a $1,000 prize for solving it, but no sequence of slides can: a single swap is an odd rearrangement, and slides only make even ones.

How many moves does a solution take?

The hardest 15 puzzle positions need 80 moves, and a random one about 50 at best. The 8 puzzle never needs more than 31. Solve finds the shortest solution on 3×3, and a short one, not always the shortest, on larger boards.

Why does one click sometimes move several tiles?

Clicking a tile in the gap's row or column slides it and every tile between it and the gap, as you would push them on a real puzzle. Moves counts each tile that moved.

Does this upload anything?

No. The puzzle is drawn on a canvas in your browser. Save downloads a PNG. Edit opens that image in the PictorX editor.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Go to Editor