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:
- 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.
- 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.
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:
- Top row. Place 1 and 2, then bring 3 and 4 in together as a pair.
- Left column. Place 5, then bring 9 and 13 in together, this time as a vertical pair.
- 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.