Exact cover solver in Python
Project description
exact cover in Python
an implementation of Donald Knuth's Dancing Links algorithm in pure Python
Usage
pip install exact_cover_py
from exact_cover_py import exact_covers
problem = np.array([
[1, 0, 0, 1, 0, 0, 1],
[1, 0, 0, 1, 0, 0, 0], # <--
[0, 0, 0, 1, 1, 0, 1],
[0, 0, 1, 0, 1, 1, 0], # <--
[0, 1, 1, 0, 0, 0, 1],
[0, 1, 1, 0, 0, 1, 1], # <--
[0, 1, 0, 0, 0, 0, 1],
])
# exact_covers returns a generator of solutions
# one solution
print(next(exact_covers(problem)))
[1, 5, 3]
# all solutions
print(list(exact_covers(problem)))
[[1, 5, 3]]
Development
# build and install locally with tests dependencies
pip install -e .[tests]
pytest
Building
pip install build
python -m build
Publishing
pip install twine
twine upload dist/*
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
exact_cover_py-0.0.1.tar.gz
(24.2 kB
view hashes)
Built Distribution
Close
Hashes for exact_cover_py-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c80cc65adcdb3a6ffba51c85a1a6a206793e552a257dd3e5cd7c50ad7e247ef |
|
MD5 | 523e5e8b75a394982687018a3807c7e1 |
|
BLAKE2b-256 | a7d5026622897051611655b2488ae885ad36eabd7935508c622a8df6e8575ec9 |