Skip to main content

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

# number of solutions
def mylen(iterable):
    return sum(map(lambda x: 1, iterable))

print(mylen(exact_covers(problem)))
2

Development

# build and install locally with tests dependencies
pip install -e .[tests]

pytest

Building and publishing

# deps
pip install build hatchling twine

# build
python -m build

# publish
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.4.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

exact_cover_py-0.0.4-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file exact_cover_py-0.0.4.tar.gz.

File metadata

  • Download URL: exact_cover_py-0.0.4.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for exact_cover_py-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7af568cebb84dae671c5b5de4284583427bb17c3d60be2641c06bdc89c782265
MD5 42382b29ad313210e6944d87571e081e
BLAKE2b-256 93f2b2423a12c28cfda713ea8aec97b3deb2f13fbbc23e060186bb4576ac86d7

See more details on using hashes here.

File details

Details for the file exact_cover_py-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for exact_cover_py-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e7136931a81171fc43602d4b49cb819bcc39a49c0c4df787dd1abc3dd423971e
MD5 83f059ad366e64ee585bb15f460f8972
BLAKE2b-256 06714395e0783eb6082cebe3030fe0910f1029c384bc1d659f06746b34fda49d

See more details on using hashes here.

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