Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A moderately fast sudoku solver in python using Algorithm X and exact cover. I did this for a module at university. [Awarded 100%]

NotificationsYou must be signed in to change notification settings

TheGogy/sudoku-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sudoku Solver using Exact Satisfactability and Algorithm X

For more information on how to use this solver, please refer tomy blog post.

How to use the solver

Solver -sudoku.py

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%]

Topics

Resources

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp