Slide Puzzle Solver

4x4 Sliding Puzzle Solver

Shortest solutions for the classic 15 puzzle, computed right in your browser.

Click a cell and type its number. Use arrows to focus, Backspace to clear, Enter to solve. Separate two-digit tiles with a space.

Solvable

Inversions: 0 + blank row from bottom: 1 = 1; an odd total is required for an even-width board.

Example: a solution for this board

910531321411687141512
Initial example board. Follow every move below to reach the solved position.

32 moves · Shortest solution

Steps 1–10

  1. Step 1: Move 7 up
  2. Step 2: Move 14 left
  3. Step 3: Move 11 down
  4. Step 4: Move 7 right
  5. Step 5: Move 13 down
  6. Step 6: Move 2 left
  7. Step 7: Move 10 down
  8. Step 8: Move 5 left
  9. Step 9: Move 1 up
  10. Step 10: Move 6 up

Steps 11–20

  1. Step 11: Move 7 right
  2. Step 12: Move 10 down
  3. Step 13: Move 2 right
  4. Step 14: Move 9 down
  5. Step 15: Move 5 left
  6. Step 16: Move 1 left
  7. Step 17: Move 3 left
  8. Step 18: Move 4 up
  9. Step 19: Move 8 up
  10. Step 20: Move 12 up

Steps 21–30

  1. Step 21: Move 15 right
  2. Step 22: Move 11 right
  3. Step 23: Move 14 right
  4. Step 24: Move 13 down
  5. Step 25: Move 9 down
  6. Step 26: Move 5 down
  7. Step 27: Move 1 left
  8. Step 28: Move 2 up
  9. Step 29: Move 6 left
  10. Step 30: Move 7 up

Steps 31–32

  1. Step 31: Move 11 up
  2. Step 32: Move 15 left

Why a 4x4 is so much harder than a 3x3

Adding one row and one column changes everything. A 3x3 has 181,440 solvable positions; a 4x4 has about 10.46 trillion. A 4x4 sliding puzzle solver can’t simply look at boards one by one until it stumbles on the answer, because there are far too many of them.

The worst positions need 80 moves, and even an ordinary scrambled 15 puzzle usually needs a long sequence. You can solve any solvable board by hand, row by row, but that method spends extra moves moving tiles out of the way and back. It finishes the puzzle without telling you how short the solution could have been. Finding that shortest path is the job of the solver.

How this 4x4 sliding puzzle solver works

The search is IDA*, short for Iterative Deepening A*. It asks a simple question over and over: “Can this board be solved in N moves?” It explores move sequences depth-first, abandons any branch that clearly can’t finish within N, and if nothing works, it raises N and tries again. The first N that succeeds is the shortest solution. Because it only remembers the current path, it uses very little memory.

What makes IDA* fast enough is a good estimate of how many moves are left, and that is where the pattern database comes in. Before you ever press Solve, the work has been done for small groups of tiles: for every way a group can be scattered across the board, the table records the fewest moves needed to bring just those tiles home. While searching, the solver looks up each group and adds the numbers together. The total never overstates the real distance, so the answer stays the shortest, but it is far sharper than counting each tile on its own.

The table is downloaded the first time you solve a 4x4 (or a 5x5) and kept in your browser’s cache, so later solves start right away. Everything runs on your device. On rare boards the search can take longer than its time limit; you then get a complete solution that isn’t the shortest, clearly labelled as such.

Parity: why half of all 4x4 boards are impossible

Exactly half of all 4x4 arrangements can never be solved. On a board with an even width, you check this in two steps:

  1. Count the inversions: read the tiles left to right, top to bottom, skipping the blank, and count every pair where a larger number comes before a smaller one.
  2. Add the row the blank is in, counted from the bottom (the bottom row is 1).

If the total is odd, the board can be solved. If it is even, it can’t. The finished board itself passes: 0 inversions plus row 1 makes 1, an odd number. Every slide keeps the parity of this total the same, so a board that starts even stays even forever.

123456789101112131514
The 14-15 puzzle: one inversion (15 before 14) plus the blank's row (1) makes 2, an even number, so it can't be solved.

This is the famous 14-15 puzzle. Sam Loyd claimed to offer a $1,000 prize to anyone who could solve it, and because the board is impossible, nobody could ever collect. Swapping any two tiles other than the blank flips the parity, which is also how you rescue an impossible board. The unsolvable sliding puzzle guide walks through more examples.

Solving a 4x4 by hand

The hand method works by shrinking the board:

  1. Top row. Place 1 and 2, then bring 3 and 4 in together as a pair.
  2. Left column. Place 5, then bring 9 and 13 in together, this time as a vertical pair.
  3. The rest is a 3x3. Tiles 6, 7, 8, 10, 11, 12, 14 and 15 now fill a 3x3 area. Solve it exactly as you would an 8-puzzle, leaving the finished row and column alone.

The pair trick is what makes this reliable: if you slot in the last tile of a row on its own, you almost always have to break the row to finish. There is a full walkthrough with diagrams in how to solve a sliding puzzle.

Frequently asked questions

Is the 4x4 solution always the shortest?

Yes, apart from one rare case. The solver normally returns the shortest possible solution, and no 4x4 board needs more than 80 moves. If a search runs past its time limit, you get a complete solution that isn't the shortest instead, and the result says so clearly next to the move count.

How long does the solver take on a 4x4?

Usually within seconds. The first 4x4 solve also downloads the pattern database, which your browser then keeps for next time. Harder boards take longer than easy ones, and the solver never leaves you waiting indefinitely: if the search runs out of time, it switches to a complete, labelled solution instead.

What is the 15 puzzle?

The 15 puzzle is the classic 4x4 sliding puzzle: fifteen numbered tiles and one empty square. You slide tiles into the gap until they read 1 to 15 in order, with the blank in the bottom-right corner. It appeared in the United States in the 1870s and is the board this page solves.

Can I solve the 14-15 puzzle?

No. A board that is solved except for 14 and 15 being swapped has the wrong parity, and no sequence of slides can fix that. Sam Loyd claimed to offer a $1,000 prize for solving it, but nobody could ever collect. The only way out is to lift two tiles and swap them back.