sudoku-solver

9×9 Sudoku solver in PHP using recursive backtracking — runs from the browser or CLI, prints solution to stdout.

Algorithm

Recursive backtracking: iterates through empty cells, tries digits 19, and backtracks on constraint violations (row, column, and 3×3 box checks).

Input format

Edit sudoku.php to define the puzzle as an 81-character string — digits 19 for known cells, 0 for empty cells:

$puzzle = new SudokuSolver("530070000600195000098000060800060003400803001700020006060000280000419005000080079");
$puzzle->solve();

Example

Input:

5 3 0 | 0 7 0 | 0 0 0
6 0 0 | 1 9 5 | 0 0 0
0 9 8 | 0 0 0 | 0 6 0

Output (stdout):

5 3 4 | 6 7 8 | 9 1 2
6 7 2 | 1 9 5 | 3 4 8
1 9 8 | 3 4 2 | 5 6 7

Usage

php sudoku.php

Or open sudoku.php in a browser for the interactive grid UI.

License

Apache-2.0 — see LICENSE.

S
Description
No description provided
Readme Apache-2.0 132 KiB
Languages
PHP 100%