Takes an unsolved Sudoku Grid as input, given as a continuous string of 81 characters.
In this Python-written project, the program prints out the final output as a 9x9 grid and uses Constraint Propagation (AC3 Algorithm) and Backtracking Search. In AC3, it checks arc consistency and enforces it by removing values from the domain of unassigned variables. The solver will try to solve it with AC3 alone, but if it fails it will resort to Backtracking Search.
Examples of sample input for the board are given below.
Clone the project (in your git directory)
git clone git@github.com:ProgrammingMonke/SudokuSolver.git
Go to the project directory
cd SudokuSolver/
Run the program
python3 SudokuSolver.py
Example Strings (used below as well)
..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..
...26.7.168..7..9.19...45..82.1...4...46.29...5...3.28..93...74.4..5..367.3.18...
Below is sample output generated by the program.
Please enter the unsolved Sudoku Grid string: ..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..
Current Board:
..3|.2.|6..
9..|3.5|..1
..1|8.6|4..
-----------
..8|1.2|9..
7..|...|..8
..6|7.8|2..
-----------
..2|6.9|5..
8..|2.3|..9
..5|.1.|3..
Finished Board w/ AC3:
483|921|657
967|345|821
251|876|493
-----------
548|132|976
729|564|138
136|798|245
-----------
372|689|514
814|253|769
695|417|382
Finished Board w/ Backtracking:
483|921|657
967|345|821
251|876|493
-----------
548|132|976
729|564|138
136|798|245
-----------
372|689|514
814|253|769
695|417|382
...
Please enter the unsolved Sudoku Grid string: ..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..
Current Board:
..3|.2.|6..
9..|3.5|..1
..1|8.6|4..
-----------
..8|1.2|9..
7..|...|..8
..6|7.8|2..
-----------
..2|6.9|5..
8..|2.3|..9
..5|.1.|3..
Finished Board w/ AC3:
483|921|657
967|345|821
251|876|493
-----------
548|132|976
729|564|138
136|798|245
-----------
372|689|514
814|253|769
695|417|382
Finished Board w/ Backtracking:
483|921|657
251|876|493
-----------
548|132|976
729|564|138
-----------
372|689|514
814|253|769
695|417|382