Sliding puzzle

Slide the numbered tiles into order with the gap at the end. Touch a tile further down the row and everything between it and the gap comes along, the way it does on a plastic one. Every board here can be finished, which sounds like a low bar and is not: half of all shuffled arrangements are impossible, and an impossible one looks exactly like a solvable one until you have thirteen tiles home and the last two swapped.

Click a tile to slide it. A whole row or column moves at once.

Moves 0

Time 0:00

Fewest -

Size

Click a tile, or use the arrow keys: the arrow says which way the tile moves, so left slides the tile on the right of the gap leftwards. Your fewest moves at each size is kept on this machine only, in this browser, and goes no further.

The thousand dollar prize that could never be claimed

The puzzle appeared in the 1870s and set off the kind of craze that gets written about in newspapers. Its invention is credited to Noyes Palmer Chapman, a postmaster in Canastota, New York. It is not credited to Sam Loyd, although Loyd claimed it for the rest of his life and is still widely believed.

What Loyd actually did was better. He sold a version with every tile in place except the last two, 14 and 15, the wrong way round, and offered a thousand dollars to anybody who could slide them into order. The prize was never claimed and was never at risk, because the puzzle he was selling cannot be solved.

It did not take long to prove. In 1879, in the American Journal of Mathematics, William Woolsey Johnson showed that the swapped board could not be reached from the finished one, and William E. Story showed that everything else can. Between them that settles the whole game: of the arrangements of fifteen tiles and a gap, exactly half can be finished and exactly half cannot, and there is no way to tell which you are holding by looking at it.

Why half of all boards are impossible

Count the pairs of tiles that are in the wrong order relative to each other, reading the board left to right and top to bottom. That count is called the number of inversions, and the finished board has none.

Now watch what a legal move does to it. Sliding a tile sideways swaps it with the gap in the same row, which moves it past no other tile and changes nothing. Sliding a tile up or down moves it past exactly three others, which changes the count by an odd number, and at the same time moves the gap one row. Those two changes always cancel out in the same way.

So there is a quantity that every legal move leaves alone, and the finished board has one particular value of it. Any board with the other value cannot reach the finished board, however long you play, because getting there would require a move that changes something no move changes. Loyd's board is exactly that: swapping two tiles flips the count by one, and one swap is all it takes.

What this page does about it

It does not shuffle. It starts from the finished board and makes random legal moves, so every board it deals is one it has already walked away from, and walking back is always possible. That is correct because of how it is built, rather than because a rule was implemented the right way round, and a rule that is easy to invert is a rule worth not depending on. The rule is implemented as well, and tested against boards whose answer is already known, including Loyd's.

Frequently asked questions

Is anything sent to a server?

No, and there is no server to send it to. The site’s security policy sets connect-src ‘none’, so the browser blocks network requests from these pages. The board is shuffled in this tab and your best counts are kept in this browser on this machine.

What do you mean half of all boards are impossible?

Exactly that. Of the twenty thousand billion or so arrangements of fifteen tiles, precisely half can be slid back into order and half cannot, and there is no way to tell by looking. The famous case is Sam Loyd's puzzle from the 1880s, sold with every tile home except 14 and 15 the wrong way round, with a prize offered for solving it. Nobody ever claimed it.

So how do you know these boards are solvable?

Because they are not shuffled. They are made by starting from the finished board and making random legal moves, and anything reached by legal moves can be got back to by legal moves. That is correct by construction rather than by a check that might be written the wrong way round. The parity rule that decides the question is implemented and tested as well, for a board that arrives from anywhere else.

Why did a whole row move when I clicked one tile?

Because that is what happens when you push a tile on a physical one. Anything between your finger and the gap slides along with it. A version that moves only the single tile touching the gap is stricter and feels broken, and it turns every move into three or four clicks.

What do the arrow keys do?

They move a tile, not the gap. Pressing left slides the tile on the right of the gap leftwards, which is what everybody expects and the opposite of the easier thing to write. Moving the gap instead means every direction is backwards, which is subtly infuriating and hard to name.

Does the fewest-moves record mean anything?

It means something on a given size and not much between them. The shortest possible solution depends entirely on which board you were dealt, so a low number is partly a good shuffle. It is kept because it is fun to beat, not because it measures skill.

Can I play it with a keyboard only?

Yes. Tab to the board and use the arrow keys. Each tile announces its number, its row and its column, so the board can be read rather than looked at.