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.3.tar.gz (97.2 kB view details)

Uploaded Source

Built Distribution

exact_cover_py-0.0.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: exact_cover_py-0.0.3.tar.gz
  • Upload date:
  • Size: 97.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for exact_cover_py-0.0.3.tar.gz
Algorithm Hash digest
SHA256 2121e4042319ea63b8c278c6db64890f3992e2fcb288f07c85c229e52c74993c
MD5 cbba55326f1dfd37ab3ac9a6304ce90a
BLAKE2b-256 94b01dff3582c4d2409b9c31b3c546f86b02815ad6b65845de34c337e57543b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for exact_cover_py-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 649cd593cd396b143c334ea030fcdb679cef750a3f2dc907cd81ba749ade2f11
MD5 ea8bfe9ddcdeb62737fb058d88568a89
BLAKE2b-256 855d9970361d173a0ae2a281adc94ce0ebc6e28591a70dba98c2e8d9f499166e

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