9×9 Sudoku solver in PHP using recursive backtracking — runs from the browser or CLI, prints solution to stdout.
Recursive backtracking: iterates through empty cells, tries digits 1–9, and backtracks on constraint violations (row, column, and 3×3 box checks).
Edit sudoku.php to define the puzzle as an 81-character string — digits 1–9 for known cells, 0 for empty cells:
sudoku.php
0
$puzzle = new SudokuSolver("530070000600195000098000060800060003400803001700020006060000280000419005000080079"); $puzzle->solve();
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
php sudoku.php
Or open sudoku.php in a browser for the interactive grid UI.
Apache-2.0 — see LICENSE.