Skip to main content

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/*

Metadata

Release files for exact-cover-py 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for exact-cover-py 0.1.1
File Size Uploaded
exact_cover_py-0.1.1.tar.gz 60.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for exact-cover-py 0.1.1
File Interpreter ABI Platform
exact_cover_py-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 118.1 kB

Release files / exact_cover_py-0.1.1.tar.gz

Download URL exact_cover_py-0.1.1.tar.gz
Size 60.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a1a16a34745d664c34014bddae4ce78d6e69e81f90c1212db72de367c6e2e412
BLAKE2b-256 checksum
How to use checksums
e9436a072b0ac3524c8bb8eb1d75a14867760e48e4da147bf464c923154d3195
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.1

Release files / exact_cover_py-0.1.1-py3-none-any.whl

Download URL exact_cover_py-0.1.1-py3-none-any.whl
Size 57.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8b665c88d0b0ff4d0df2c850f282e041bd1dd2518299e1526b8dc7da3c3aace
BLAKE2b-256 checksum
How to use checksums
d4a58244056409db4b303213ebed1d6b745ea1981f06584f68778844f66d514b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.1

Release history Release notifications | RSS feed

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page