Sliding Puzzle Solver
Solve a numbered 2x2, 3x3 or 4x4 sliding puzzle from your start board to any goal board you enter. Type tiles or swap squares, check solvability, then follow each slide with Next or Play. IDA* and breadth-first prove shortest solutions on 2x2 and 3x3; 4x4 IDA* stops at your node limit. Row by row can find a 3x3 or 4x4 solution that may be longer than the shortest.
Select a square, then another on the same board, to swap them. Arrow keys move between squares, Enter or Space selects, Escape lets go. Editing the squares rewrites the text.
- parity
- 10 inversions, even, same as the goal's 0, even: solvable
- lower bound
- Manhattan 14 + linear conflicts 2 = 16
- search
- IDA*, exhaustive on 3 x 3
- node limit
- not used: this search always finishes
Loading any saved boards.
- Moves
- none yet
- Lower bound
- 16 (Manhattan 14)
- Inversions
- 10, even
- Playback
- none
Solution as text
Sliding puzzle, 3 x 3 Start 2 1 6 7 _ 8 3 4 5 Goal 1 2 3 4 5 6 7 8 _ Solver: IDA* Parity: 10 inversions, even, same as the goal's 0, even: solvable Result: not solved yet
Examples
Each one loads both boards and the solver, then solves at once. The line with each one is what the solver says.
- 0 moves: already solved
- unsolvable: 1 inversion against the goal's 0, so no run of slides can reach it
- 18 moves, proven shortest, replayed slide by slide to the goal
- 26 moves, proven shortest, replayed slide by slide to the goal
- 32 moves, proven shortest, replayed slide by slide to the goal
- unresolved at the 1,000 node limit: at least 26 moves
- 36 moves, not proven shortest, replayed slide by slide to the goal
- unsolvable: inversions plus the blank's row make 5 against the goal's 4, so no run of slides can reach it
Common questions
- Why does it say my sliding puzzle is unsolvable?
- Every slide swaps the blank with one tile, and one count keeps its parity through every slide. Read the tiles row by row with the blank left out and count the pairs that are out of order, the inversions. On a 3 x 3 board a slide never changes whether that count is odd or even; on 2 x 2 and 4 x 4 boards, add the blank's row counted from the top, and that sum keeps its parity instead. If the start and the goal disagree, no run of slides joins them, so exactly half of all arrangements can never reach a given goal. A solved 4 x 4 with 14 and 15 swapped is the famous case: 1 inversion plus the blank's row 4 makes 5, against the goal's 4.
- Is the answer the shortest possible?
- Only where it says proven shortest. IDA* and breadth-first rule out every shorter sequence before they answer, and on 2 x 2 and 3 x 3 boards they always finish, so every answer there is a shortest one; other answers of the same length may exist. On 4 x 4, IDA* is proven shortest when it finishes inside your node limit; if it reaches the limit first it says unresolved and gives a proven minimum, such as at least 26 moves. Row by row is quick and can be longer than the shortest; it is called shortest only when its length equals the lower bound.
- How long does a 4 x 4 (15 puzzle) search take?
- A 4x4 IDA* search depends on the board and your device. It stops at your node limit, 100,000,000 by default, with a permitted range of 1,000 to 1,000,000,000. If it stops early, the result is unresolved with a proven lower bound, not a move sequence. Cancel stops a running worker. Choose Row by row to seek a solution without proving it shortest; when a worker cannot start, that option can still run on the page.
- How do I enter my puzzle?
- Type the tiles into the text field under each board in reading order, row by row from the top, with 0, _ or . for the blank, for example 1 2 3 / 4 5 6 / 7 8 _. Spaces, commas, slashes and semicolons all separate tiles. Or select a square and then another square on the same board to swap them; with a keyboard, the arrow keys move between squares and Enter or Space selects. The goal can be any arrangement: two buttons set the tiles in order with the blank last or first, and Shuffle start deals a random board that is always solvable.
- What do the moves mean?
- Each number is the tile that slides into the blank, in order, and the line under it gives the way each tile moves: U up, D down, L left, R right. Some apps list the blank's moves instead, which run the opposite way. Step through the answer with First, Back, Next and Last or the step slider, or press Play to watch it; the board marks the tile that just moved, and Copy puts both boards and the answer on the clipboard as text. If either board text is invalid, fix its error before copying.
- What is the difference between IDA*, breadth-first and row by row?
- IDA* searches in rounds, each round allowing a longer answer, and skips any line that a lower bound (Manhattan distance plus linear conflicts) shows cannot fit, so it needs very little memory. Breadth-first visits every board one move away, then two, and so on, keeping all of them in memory, which is why it runs on 2 x 2 and 3 x 3 only: a 3 x 3 start can reach 181,440 boards. Row by row places the tiles of one outer row, then one outer column, and then solves the smaller board left over with IDA*.
- Can it solve a picture puzzle or a larger board?
- The tool accepts numbered square boards of 2x2, 3x3 and 4x4. It has no image upload or picture-piece matching, and cannot enter a 3x4, 5x5 or 8x8 board. General block puzzles with differently sized pieces or multiple gaps are also unsupported.
- Is my puzzle sent anywhere?
- No. Every search runs in your browser, in a background worker where the browser can start one, and the boards and settings are saved in this browser's local storage so they are there next time.
- Does this use AI, and can I use it on a phone?
- It uses classic puzzle-search algorithms, including the Manhattan-distance heuristic in IDA*, rather than a trained AI model. The solver runs in a browser on a computer or phone. Select the board size, enter Start as text and Goal as text, then press Solve. No installation is needed.
A move count is called shortest only when it is proven, by an exhaustive search (IDA* and breadth-first finish one on every 2 x 2 and 3 x 3 board) or by equalling the lower bound; a 4 x 4 IDA* search that reaches your node limit says unresolved and gives the lower bound it proved. Solvability is decided exactly from tile parity before any search, and every returned sequence is replayed move by move to the goal before it is shown.