- Notifications
You must be signed in to change notification settings - Fork0
TheGogy/sudoku-solver
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
For more information on how to use this solver, please refer tomy blog post.
To use the solver, pass anumpy.ndarray((9x9)<sudoku>)
tosudoku.py
. The test script included (test_sudoku.py
) contains examples of how to do this and examples of input are stored in numpy arrays in/data/
.
importnumpyasnpfromsudokuimportsudoku_solverinitial_state=np.ndarray((9,9),<yoursudokuhere>)solution=sudoku_solver(initial_state)...
The solver will return the solved sudoku in the formnumpy.ndarray((9x9)<solution)
. If the sudoku has multiple possible solutions, the solver will return the first one it finds.
Test script -test_sudoku.py
I have included a test scripttest_sudoku.py
, that implements the test packagetest_scripts.py
(see below) with the sudoku solver.
Usage is as follows:
Usage: test_sudoku.py [ -q , -p , -o , -h|-n|-m|-f ] <batches | filename>Tests sudoku solver with various puzzles.Options: -h, --help Show help. -n, --normal Run test as normal. -m, --multiple Run <batches> tests of normal test. -f, --file Solve a sudoku stored in a file [*.txt, *.npy] -o, --output-to-file Output the solutions to a .npy file (use with -f) -p, --use-process-time Use time.process_time() instead of time.perf_counter() -q, --quit-after Stop solving sudokus after it has solved a certain number. Used with "-f" on .npy and .csv files.
About
A moderately fast sudoku solver in python using Algorithm X and exact cover. I did this for a module at university. [Awarded 100%]