> to navigation > to content

Scripting Corner

PHP:
Sudoku Class

view source code

Sudoku input

Sudokus are read serialized, i.e. as a string of consecutive fields line by line starting from the top left corner ending at the bottom right. Every symbol (except SPACE) which is not an element of the character set (set below) is treated as an empty field. You can use line breaks at the end of lines to make things easier.
Sudoku Examples.

character set


used algorithms for the solver





Sudoku examples

4×4

0 1 2 0 0 0 1 0 3 0 0 1 0 0 0 0

9×9

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

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

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

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

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

0 9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 0 11 0 8 0 0 6 16 0 0 5 9 0 0 13 0 12 13 0 0 14 0 9 15 0 5 0 0 2 4 0 0 11 0 0 6 0 4 0 0 10 0 16 7 0 0 1 0 0 0 8 0 0 0 16 1 11 0 15 6 0 0 0 13 0 2 0 0 4 12 8 5 0 14 0 0 3 15 0 0 9

14 0 7 9 16 11 0 3 0 5 2 0 0 0 0 8 0 0 0 8 0 0 0 0 13 16 4 0 0 6 14 15 0 0 0 0 0 0 4 5 6 8 0 0 16 0 0 7 0 0 0 0 13 0 15 6 7 0 0 1 3 0 9 10 11 3 0 0 4 13 0 0 0 0 0 8 2 0 6 0 9 7 0 0 0 0 10 11 0 0 0 14 0 13 0 0 10 8 6 16 0 7 3 14 0 0 13 0 0 12 0 11 5 0 0 14 0 1 0 0 0 4 0 12 0 9 7 3 15 0 9 0 0 0 0 4 0 1 0 16 7 3 8 13 4 14 1 2 9 16 7 0 0 3 0 0 0 0 0 6 8 0 11 6 0 15 0 0 0 0 0 0 4 0 0 0 7 13 0 0 0 0 0 0 2 0 9 0 0 16 15 0 0 0 0 0 0 12 0 1 15 0 0 13 0 0 0 0 0 1 15 0 11 0 0 0 0 2 8 0 9 0 10 0 2 10 0 12 0 0 0 7 0 0 14 0 0 1 16 0 3 0 16 0 0 4 6 8 0 9 10 0 15 0 0 12