Skip to main content

Exact cover solver in Python

Project description

exact cover in Python/numba using algorithm X

an implementation of Donald Knuth's Dancing Links algorithm X in Python / numba

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

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

Uploaded Source

Built Distribution

exact_cover_py-0.1.2-py3-none-any.whl (57.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for exact_cover_py-0.1.2.tar.gz
Algorithm Hash digest
SHA256 52e8146f99c9116d80d20d8caff2a7e1281900bbb00afa5257c5068985e5c7bc
MD5 63584f49a57ab6808efa3809850e4494
BLAKE2b-256 514a31ce33da7c723df17945b40784afaca2cb5bd190c69394c021395ab9b527

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for exact_cover_py-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 26548ddeca50753064bea8f42f0839d13d7472ba981e3d561a7d0995fb938239
MD5 d6c975497f2da30392bb8425be1ae36a
BLAKE2b-256 76ad831f297e80ac36467595f91180acdac541e4c4a50c4e5c861641330cbfe7

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