Toolvito

Calculates on this device. File exports run online.

Sliding Puzzle Solver

Type the board as it is now, with 0 for the empty space. The page finds the moves to the goal, shows the board after every move, and says when a position cannot be solved.

Enter your values

Your values

One row per line, tiles separated by spaces, 0 (or _) for the empty space. 2 × 2 up to 8 × 8. The goal is 1, 2, 3, … in reading order with the empty space last.

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose Solve.

Download the steps

Task
PDF to print: the start and every step

The start board on one page, then the boards after each move (the first 120).

More options

With 2, 4 or 6, the pictures share a page at one scale; the steps start on their own page.

The calculator above works on your device. When you run a task in this section, Toolvito receives the values and result you submit to make the file or run the check. Download the result within one hour after the job finishes. Choose Delete files now to request earlier removal. The hourly cleanup normally removes files within one to two hours after completion.

How to solve a sliding puzzle

  1. In Board, type one row per line, the tiles separated by spaces and 0 (or _) for the empty space, such as 1 2 3 / 4 0 6 / 7 5 8.
  2. Choose The shortest (for 3 × 3 and 4 × 4 boards) or Step by step (quick, for any size).
  3. Press Solve. You get every move (“5 down” means tile 5 slides down into the empty space) and a picture of each step.

Can it be solved?

Only half of all positions can be solved. Count the inversions: the pairs of tiles in the wrong order when you read the board row by row, leaving out the empty space. With an odd width (3 × 3, 5 × 5) the number of inversions must be even. With an even width (4 × 4, 6 × 6) the inversions plus the row of the empty space counted from the bottom must be odd. This rule was proved by Johnson and Story in 1879.

Worked example: on 1 2 3 / 4 5 6 / 8 7 0 only the pair 8, 7 is in the wrong order: 1 inversion, an odd number, so this 3 × 3 board cannot be solved. Swap two tiles back to get a position that can.

How the shortest solution is found

For boards up to 4 × 4 the page uses IDA* (iterative deepening A*, Korf 1985). It never overestimates the moves left: it adds up how far each tile is from its place (the Manhattan distance) and 2 moves for each tile that must step out of a row or column to let another one pass (the linear conflict). So the first solution it finds is a shortest one. The hardest 8-puzzle positions need 31 moves.

The search has a limit of 20 million positions. A very hard 15-puzzle can need more; then the page says so and gives a step-by-step solution instead.

Larger boards and step by step

A step-by-step solution places the top row tile by tile (the last two together), then the left column, and so on, until a 3 × 3 is left, which is solved by the shortest search. It always works and is quick, but it is not the shortest.

Picture puzzles

A sliding picture puzzle works the same way: number the pieces 1, 2, 3, … in the order they belong (row by row), type the number of the piece in each place, and follow the moves.

Limits you should know

  • Square boards of 2 × 2 to 8 × 8 with numbered tiles, the goal 1, 2, 3, … with the empty space in the bottom right corner.
  • Puzzles with blocks of different sizes (such as Klotski or rush hour) are not solved here.
  • The pictures show the first 120 moves; the list has them all.

Privacy

The puzzle is solved in your browser. Only when you use one of the boxes below are the drawings (and, for a document, the result) sent to the Toolvito server to make the file. Download the result within one hour after the job finishes. Choose Delete files now to request earlier removal. The hourly cleanup normally removes files within one to two hours after completion.

Related tools