PlayNook

Math & Logic · Parity

15 Puzzle

Slide the numbers into order. The catch nobody tells you: half of all possible scrambles cannot be solved at all, and you cannot see which by looking. This one tells you, and shows the arithmetic.

Slide the numbered tiles into order. Everybody has met this puzzle, usually in plastic, usually on a train.

What almost nobody is told is that half of all possible scrambles cannot be solved — not by you, not by anyone, not with unlimited time. And you cannot tell which by looking at them.

How to play the 15 puzzle

Tap any tile in line with the gap and it slides in. Tap one further along the same row or column and the whole row slides at once, exactly as it would under your finger. Green tiles are already home.

The panel under the board is the part that matters. It counts the arrangement after every move and tells you whether the thing in front of you can come out — and shows the arithmetic that decides it.

Is my sliding puzzle solvable?

Count the inversions: read the tiles in order, row by row, ignoring the gap, and count every pair that appears the wrong way round.

Sam Loyd's 14-15 board with the count worked out: one inversion, blank in row one from the bottom, total two, even — and it has to be odd
Computed by the engine that runs the game. One inversion, the gap in row 1 from the bottom, total 2 — even, and on a four-wide board it has to be odd.

Then:

  • Odd number of columns (3×3, 5×5) — solvable if the inversion count is even.
  • Even number of columns (4×4) — add the row the gap is in, counted from the bottom starting at 1. The total has to be odd.

That second line is where most explanations go wrong. Some count the row from the top, some forget the board width matters at all, and both mistakes give you the right answer exactly half the time — which is indistinguishable from working.

We did not want to be one of those pages, so we checked. For the 3×3 there are only 362,880 arrangements, so every one can be tested: we walked the puzzle outwards from the solved board to find everything reachable, then compared the rule against that list. It agreed on all 362,880.

Why half of them are impossible

Two 4x4 boards side by side, identical except that two tiles have swapped places; one is labelled solvable and the other never solvable
The same board twice, with one pair exchanged. One comes out; the other cannot be solved by anyone. The counts underneath are the only visible difference.

Every slide changes the inversion count and moves the gap. It turns out those two changes always cancel out in one particular combination — slide a tile sideways and the inversion count does not change at all; slide one vertically and it changes by an odd number, but the gap also changes row. The combined parity is untouched.

A quantity the rules cannot change is called an invariant, and this is the tidiest one in recreational mathematics. The solved board has one value of it. Every arrangement with the other value is in a separate world you can never slide into — 181,440 on one side and 181,440 on the other, for the 3×3.

There is a button on this page that deals a deliberately impossible scramble, and another that swaps two tiles. Press the second one and watch the verdict flip while nothing else changes. That is the whole proof, in one click.

The $1,000 prize that was never in danger

In the 1880s Sam Loyd offered a thousand dollars to anyone who could solve a board that was complete except for the 14 and the 15 being the wrong way round. It drove people to distraction. It was also perfectly safe: one swap gives one inversion, the gap sits in row 1 from the bottom, and 1 + 1 = 2 is even — the wrong side of the line on a four-wide board.

Loyd also claimed for the rest of his life that he had invented the puzzle. He had not. It was Noyes Palmer Chapman, a postmaster in New York state, around 1874; the claim went unchallenged for over a century until Slocum and Sonneveld traced the history in 2006. What Loyd invented was the impossible version, and the prize that made it famous.

How many moves can the 15 puzzle take?

A distribution of all 181,440 reachable 3x3 arrangements by the number of moves they need, peaking at 24 moves and ending at 31
Every reachable arrangement of the 3×3, measured by walking outwards from solved. The peak is 24 moves; the far end is 31, and only two arrangements are there.

For the 3×3 we know exactly, because we counted. The hardest arrangements need 31 moves, and there are only two of them. The commonest distance is 24 moves. And almost nothing is nearly solved: just 51 of the 181,440 are within five moves.

That last number explains why the puzzle feels the way it does. A random scramble is not somewhere near the answer — it is out in the fat middle of the distribution, two dozen moves away, and there is no shortcut that finds them.

Why nobody has solved the 5×5

A table of the 3x3, 4x4 and 5x5 puzzles with their number of arrangements, from 362,880 up to more than fifteen septillion
Board size against the number of arrangements. Half of each figure is reachable; the other half is the world you cannot slide into.

The 3×3 has 362,880 arrangements and we walked all of them in a few seconds. The 4×4 has 20,922,789,888,000, which is past what a browser tab can enumerate — the answer for the hardest board, 80 moves, took a dedicated computation and was settled in 2010. That figure is not ours and we have not repeated it.

The 5×5 has more than fifteen septillion. Nobody knows its worst case, and on current hardware nobody is going to.

Which is the quiet pleasure of this puzzle: the rule that tells you whether a board can be solved takes a few seconds with a pencil and works at any size, while actually solving one gets impossible almost immediately. Knowing that something is possible and knowing how are very different problems, and the 15 puzzle keeps them in the same box.

If you like a puzzle whose answer is fixed before you start, the Towers of Hanoi is the other one; and Knight's Tour is the one where you can see the rule working while you play.

Frequently asked questions

+ Is every 15 puzzle solvable?

No — exactly half of all arrangements cannot be solved, no matter how long you slide. It is not a matter of skill or patience: the two halves are separate worlds, and sliding tiles can never take you from one to the other. The only way across is to lift two tiles out and swap them.

+ How do I know if my sliding puzzle is solvable?

Count the inversions — every pair of tiles that appears in the wrong order when you read the board row by row, ignoring the gap. On a board with an odd number of columns (3×3, 5×5) the arrangement is solvable if that count is even. On a board with an even number of columns (4×4) add the row the gap is in, counted from the bottom starting at 1: the total has to be odd. The panel under the board on this page does exactly that after every move.

+ Why does half of it not work?

Because one number never changes. Every single slide changes the inversion count and the gap's row together, in a way that always leaves that combined parity as it was. It is what mathematicians call an invariant — a quantity the rules cannot touch. Since the solved board has one value of it, every arrangement with the other value is permanently out of reach.

+ How many arrangements are there?

20,922,789,888,000 for the 4×4 — that is 16 factorial — and half of them, 10,461,394,944,000, can actually be reached. For the 3×3 the numbers are small enough to check by brute force, and we did: of 362,880 arrangements exactly 181,440 are reachable. Our parity rule agreed with the search on every single one.

+ What was Sam Loyd's 14-15 puzzle?

In the 1880s Sam Loyd offered $1,000 to anyone who could solve a board that was complete except for the 14 and 15 being the wrong way round. He was never at risk. That single swap gives one inversion, the gap sits in row 1 from the bottom, and 1 + 1 = 2 is even — which on a four-wide board means unsolvable. The prize was safe because the arrangement is on the wrong side of the divide.

+ Who actually invented the 15 puzzle?

Noyes Palmer Chapman, a postmaster in New York state, around 1874. Sam Loyd claimed for decades that he had invented it, and the claim stuck for over a century until Slocum and Sonneveld traced the real history in 2006. Loyd did not invent the puzzle — he invented the impossible version and the prize that made it famous.

+ What is the hardest possible 3×3 scramble?

31 moves. We walked all 181,440 reachable arrangements of the 8 puzzle and found the distance of every one: the very worst are exactly 31 moves from solved, and there are only two of them. The commonest distance is 24 moves, and just 51 arrangements are within five moves of solved.

+ How many moves does the worst 15 puzzle take?

80. That answer needed a dedicated computation and was settled in 2010 — it is not ours and we have not repeated it. For the 5×5 nobody knows, and on current hardware nobody is going to.

+ Is it free?

Yes, and there is no sign-up. Your best move count for each board size is kept in your own browser.

More games like this

Tangram — screenshot of the browser gamePuzzle
Dissection Puzzle1 Player

Tangram

Seven flat pieces cut from one square. They always cover the same area, so every silhouette needs all seven — the only question is which way round they go.

  • All thirteen convex shapes, ordered easiest to hardest by solutions we counted
  • Pieces snap to corners, so a solution is exact — never almost
  • The famous square is last: it has exactly one solution
Play Tangram
Peg Solitaire — screenshot of the browser gameMath & Logic
Solitaire Puzzle1-2 Players

Peg Solitaire

Thirty-three holes, one rule and exactly thirty-one jumps — never more, never fewer. What varies is only whether you strand yourself before the end.

  • Undo as far back as you like — this is a puzzle, not a test
  • Always exactly 31 jumps, and we show why that is not a coincidence
  • A colouring rules out 28 of the 33 possible endings before you move
Play Peg Solitaire
Knight's Tour — screenshot of the browser gameMath & Logic
Graph Theory1-2 Players

Knight's Tour

A knight, every square once, and never the same square twice. The rule that solves it is on the board while you play — and there is a two-player game hiding in the same rules.

  • Warnsdorff's number printed on every square you can reach
  • A duel for the same knight — online, with a table code
  • Boards from 5×5 to 8×8, and the ones that have no tour at all
Play Knight's Tour
Towers of Hanoi — screenshot of the browser gameMath & Logic
Recursion1 Player

Towers of Hanoi

The puzzle where the answer is known before you start: 2ⁿ−1 moves, never fewer. The question is whether you can find them — and the counter says the instant you cannot.

  • Three to ten discs, with the target 2ⁿ−1 always in view
  • A counter that tells you the moment you leave the shortest path
  • Watch it solve itself, slowly, and see the recursion
Play Towers of Hanoi