An Optimized Sudoku Solver
An optimised backtracking sudoku solver, that only iterates for the narrowed down possibilities, includes usual unoptimized backtracking too
Implements multi-threading, using upto 9 threads during optimisation, for each row.
And, if you have any questions about this or related, even what may seem dumb to you, feel free to start an issue, or dm me on twitter π
Building
Windows
Two Ways ->
-
If you have MSVC compiler, open vs code from Visual Studio Developer Command Prompt, and click
Ctrl + Shift + B
to run the default build task -
Using CMAKE,
cd build cmake .. cmake --build .
* Or open the .sln solution file using visual studio then get executable
Using either way, you will get a sudokuSolver.exe, on a succesful build, that's it ! π
Linux
-
Using CMAKE and makefiles-
cd build cmake .. make .
This will provide you with an executable named
sudokuSolver
, on a successful build π
Fun Fact - This time i have more build methods for Windows, not Linux... quite rare π
Working -
-
The
sudoku
class (sudoku.hpp) is the primary class, and usesbox<>
(box.hpp) as elements of 9x9 grid (for now, they just store a single value) -
The
sudoku::board
is the grid storing the actual values... andEMPTY
is an enum var equating to0
.sudoku::_possibilities
is also a 2D array, storingstd::set
of possible values at that index -
sudoku::optimise
iterates through each row, assigns possibile values to each cell... then iterate through each column, and then each 3x3 block, thereby reducing the possibilities, and hence the recursion depth -
sudoku::solve
applies simple backtrakking to solve the board, ifsudoku::optimise
has been called earlier, then the optimised vairant ofsudoku::backtrackSolve_opt
will be used, elsesudoku::backtrackSolve
If you want more detail about something else, or more briefing on the above ones, do raise an issue :D
Further Improvements -
-
sudoku::optimise()
can be populated with more sudoku tricks, like naked triplets/pairs and others.You may refer https://bestofsudoku.com/sudoku-strategy for some strategies