Tool/solver to solve a 3x3 puzzle in an instant: check the solvability of a configuration and get detailed solving steps.
8-Puzzle Solver - dCode
Tag(s) : Number Games, Board Games
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
A 3x3 sliding puzzle, also called an 8-puzzle, is a game consisting of a grid of 9 squares (3 rows and 3 columns) containing 8 numbered tiles from 1 to 8 and one empty square.
The objective is to rearrange the tiles in ascending order (usually from 1 to 8, with the empty square in the last position) by successively sliding an adjacent tile towards the empty square, in any direction (up, down, left or right).
A 3x3 configuration is solvable if the total number of inversions in the sequence of tiles (ignoring the empty space) is even.
An inversion is a pair of tiles $ (i, j) $ such that $ i > j $ and $ i $ appears before $ j $ in a row-by-row reading (from left to right, then top to bottom), ignoring the empty tile.
If $ I $ is even, the configuration has a solution.
If $ I $ is odd, the configuration is unsolvable and has no solution.
Example: Configuration [1, 2, 3, 4, 5, 6, 8, 7, 0]: there is only one inversion $ (8, 7) $, so $ I = 1 $, and since $ I $ is odd, this configuration is unsolvable.
Several variations exist:
— N Ă— N sliding puzzle: larger grids (15-puzzle, 24-puzzle, etc.). The search complexity increases rapidly.
— Puzzle with constraints: some squares may be blocked or certain moves prohibited.
— Toroidal sliding puzzle: the left/right and top/bottom edges are connected.
— Higher-dimensional sliding puzzle: extensions into 3D where moves occur in a volumetric space.
Each variation modifies the combinatorial structure of the problem and its solvable properties.
The total theoretical space of arrangements of the 9 squares is $ 9! = 362880 $. However, only half of these configurations are attainable due to the parity constraint of the permutations. The exact number of solvable configurations is therefore: $ \frac{9!}{2} = 181440 $. This means that there are 181440 distinct starting positions.
For the 3x3 (8-puzzle), the maximum number of optimal moves required to solve a solvable position is 31. This bound was determined by computer-assisted exhaustive exploration.
dCode retains ownership of the "8-Puzzle Solver" source code. Any algorithm for the "8-Puzzle Solver" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "8-Puzzle Solver" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "8-Puzzle Solver" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "8-Puzzle Solver" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: 8-Puzzle Solver on dCode.fr [online website], retrieved on 2026-02-22,