The app “Slide Puzzle” makes a new puzzle on the spot every time you play. Simply arranging the tiles at random would make half of the puzzles unsolvable, so the method has a little twist.
1. Shuffle every square
First, all the squares, tiles and empty space together, are rearranged at random, like shuffling a deck of cards. The shuffle used makes every arrangement equally likely (the Fisher–Yates shuffle).
2. If it is unsolvable, swap two tiles
Half of the shuffled arrangements can never be solved, no matter how you move them (Unsolvable positions and parity). So the app counts things like the inversions to check whether it can be solved, and if the arrangement is unsolvable, it swaps the first two tiles other than the empty space (the first and second tiles reading from the top left).
Swapping two tiles always flips between solvable and unsolvable, so this always gives a solvable arrangement.
With this method, you know the puzzle can be solved without ever solving it.
3. If it is not scrambled enough, deal again
A random shuffle can now and then produce a board that is almost solved. The app deals again (up to 64 times) if a board does not meet both of these conditions.
- The total distance of the tiles from their correct places is at least a set number.
- A quarter or fewer of the tiles are in their correct places.
| Difficulty | Board | Minimum total distance | Random average |
|---|---|---|---|
| ★1 | 3×3 | 11 | 14.0 |
| ★2 | 4×4 | 30 | 37.0 |
| ★3 | 5×5 | 62 | 76.0 |
| ★4 | 6×6 | 110 | 135.1 |
| ★5 | 7×7 | 175 | 218.1 |
Each minimum is about 80% of the average for random arrangements. A redeal happened about 14% of the time on ★1, about 7% on ★2, and only around 0.2% on ★5 (each rate from 20,000 trials).
The same seed gives the same puzzle
The app makes each puzzle from a number called a “seed,” using random numbers that follow a fixed procedure. The same seed and the same difficulty always give the same puzzle. For example, with seed 42, ★1 and ★2 give these puzzles.
The boards in this site’s articles and on the Play for free page also make puzzles with the same procedure as the app, and we have confirmed that the same seed gives the same puzzle as in the app.
Why not mix by sliding?
If you mix by sliding tiles from the solved board, the puzzle you make can always be solved. The catch is that it takes a lot of slides to mix things up well.
On a 4×4, here is the average total distance after sliding one tile at a time in random directions (not counting a move that immediately undoes the previous one).
| Slides | Average total distance |
|---|---|
| 20 | 15.2 |
| 50 | 24.3 |
| 100 | 30.7 |
| 200 | 35.5 |
| 500 | 37.0 |
To get close to the average for a randomly arranged board (37.0), you need hundreds of slides. A 7×7 would need even more. Shuffling everything and then fixing the parity makes a well-mixed puzzle in one step, on any board size.
When you mix a handmade sliding puzzle, it is safest to slide the tiles without taking them out of the frame (Making a sliding puzzle at home).
