How to play the 8 puzzle
Tap or click a tile next to the empty square to slide it in; tap one further along the same row or column to slide the whole line. With a keyboard, click the board and use the arrow keys. Put the tiles in order, 1 2 3 on top, 4 5 6 in the middle and 7 8 on the bottom, with the gap in the bottom-right corner.
How to solve the 8 puzzle in three steps
- Top row: 1, 2, 3. Slide 1 into the top-left corner. Then bring 2 and 3 in together: park 3 where 2 belongs, 2 directly below it, and walk the gap round to the top-right corner without going through the top row. Slide 3 right, then 2 up.
- Left column: 4 and 7. Put 7 where 4 belongs, 4 just to its right, and the gap under 7. Slide 7 down, then 4 left.
- The last square: 5, 6 and 8. Move the gap around the bottom-right 2×2 square, always in the same direction, until all three are in place.
The same idea scales up to every sliding puzzle. Our guide to solving any sliding puzzle walks through it in detail.
The 8 puzzle by the numbers
- 362,880 ways to arrange the board (9!), and exactly half of them, 181,440, can be solved.
- 31 moves solves any of them. The hardest positions need exactly 31; we checked by searching all 181,440.
- Even: on a 3×3 board, a position can be solved exactly when the number of inversions (pairs of tiles in the wrong order, reading row by row and ignoring the gap) is even.
Why computer scientists love the 8 puzzle
The 8 puzzle is small enough to search completely and big enough to be interesting, so it's a favourite example in artificial intelligence courses. Students use it to compare search algorithms such as breadth-first search and A*, with simple rules of thumb such as "how many tiles are out of place" or the Manhattan distance, the total number of rows and columns each tile is from home. Those same ideas help people too: fix the tiles that are furthest from home first.
Questions about the 8 puzzle
What is the 8 puzzle?
The 8 puzzle is a sliding puzzle with eight numbered tiles on a 3×3 board and one empty space. You slide the tiles into order, 1 to 8, with the gap in the bottom-right corner.
What is the most moves an 8 puzzle can need?
31. Every solvable 8 puzzle can be solved in 31 single-tile moves or fewer, and the hardest positions need exactly 31.
Is every 8 puzzle solvable?
No. Only half of the 362,880 ways to arrange the board can be solved. On a 3×3 board a position can be solved exactly when the number of inversions (pairs of tiles in the wrong order) is even. Every puzzle on slidingblock.app can be solved.