Skip to main content

Solve sudoku using an 'exact cover' algorithm.

Project description

xudoku - Solve sudoku using an 'exact cover' algorithm

PyPI version Run tests, lint, build Deploy to pypi

This is the sudoku code from @moygit's project 'exact_cover_np'.

The package is maintained by me, @jwg4.

I separated the code for the 'exact cover' algorithm (now available at https://github.com/jwg4/exact_cover) from the sudoku code and created this package. At that package you can find more info about the exact cover algorithm, which can be used for lots of combinatoric problems.

How to use the package

>>> import xudoku
>>> s = xudoku.Sudoku(9)
>>> s.read("tests/files/insight.csv")
>>> sol = s.solve()
>>> sol._sudo.tolist()
[[1, 3, 5, 2, 9, 7, 8, 6, 4], [9, 8, 2, 4, 1, 6, 7, 5, 3], [7, 6, 4, 3, 8, 5, 1, 9, 2], [2, 1, 8, 7, 3, 9, 6, 4, 5], [5, 9, 7, 8, 6, 4, 2, 3, 1], [6, 4, 3, 1, 5, 2, 9, 7, 8], [4, 2, 6, 5, 7, 1, 3, 8, 9], [3, 5, 9, 6, 2, 8, 4, 1, 7], [8, 7, 1, 9, 4, 3, 5, 2, 6]]
>>> s._hardness
'Easy'

Currently the puzzle data can only be read from CSV. You could use io.StringIO, which turns a string into a file-like object, if you want to generate your sudoku puzzle in code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xudoku-1.0.0.tar.gz (11.2 kB view hashes)

Uploaded Source

Built Distribution

xudoku-1.0.0-py3-none-any.whl (11.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page