Skip to main content

Some exact cover problems and their solutions

Project description

exact cover samples

contains some exact cover samples together with their solutions.

installation

pip install exact-cover-samples

usage

problems

from exact_cover_samples import problems

problems is a dictionary with the following structure:

{ "shortname": function, ... }

where shortname is a string and function is a function that in turn returns a dictionary with the following structure:

{
    "shortname": str,               # short name of the problem
    "name": str,                    # long name of the problem
    "data": np.ndarray,             # of ndim=2 and dtype=bool
    "solutions": list[list[int]]    # each solution is a list of indices in data
}

in some cases `solutions` is an nd-array too - see below how to canonicalize for comparing solutions.

summary

you can display a summary of the available problems by running the following code:

from exact_cover_samples import summary

summary()
# or to filter a bit
summary("pent")

canonical representation

p = problems["knuth-original"]()
s = p["solutions"]
type(s)
-> list
type(s[0])
-> tuple
type(canonical(s))
-> set

p = problems["pentomino-chessboard"]()
s = p["solutions"]
type(s)
-> numpy.ndarray
type(canonical(s))
-> set

so that as long as your code produces solutions as an iterable of iterables, you should be able to use canonical to compare them like so

# import this module
import exact_cover_samples as ecs
# import a solver module
from exact_cover_py import exact_covers

# get a problem
p = ecs.problems["knuth"]()
# get the expected solutions
expected = p["solutions"]
# get the computed solutions
computed = exact_covers(p["data"])
# compare them
assert ecs.canonical(expected) == ecs.canonical(computed)

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_samples-0.0.2.tar.gz (92.6 kB view details)

Uploaded Source

Built Distribution

exact_cover_samples-0.0.2-py3-none-any.whl (90.4 kB view details)

Uploaded Python 3

File details

Details for the file exact_cover_samples-0.0.2.tar.gz.

File metadata

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

File hashes

Hashes for exact_cover_samples-0.0.2.tar.gz
Algorithm Hash digest
SHA256 bedf90cd32f82fc04c95c0497a9770e5721cd043f2248808a379b6ba6261d3ff
MD5 a90244bc699989ba6466d7d7009378dc
BLAKE2b-256 64377914159370955f29ad9bcbdf2627390ad980c97b40a0cdf3279e8c4f1817

See more details on using hashes here.

File details

Details for the file exact_cover_samples-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for exact_cover_samples-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6fbeae60572d30e68f258bb5d542c8d3bfe5eb8e74fbba143299ae0bd9f8283e
MD5 78b714eec151a661a96753e9f7a0a77a
BLAKE2b-256 de38b34342a8200fa3b5c90ecac56207f2ade7cc3ac4378653cd6f2b08e020b7

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