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.5.tar.gz (11.4 MB view details)

Uploaded Source

Built Distribution

exact_cover_samples-0.0.5-py3-none-any.whl (313.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: exact_cover_samples-0.0.5.tar.gz
  • Upload date:
  • Size: 11.4 MB
  • 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.5.tar.gz
Algorithm Hash digest
SHA256 31d04f247373021668fc7c0c395e0bb16b8f3cf9848fdf71439a2ae87e49f8a3
MD5 c0551c0b2ef03a35aff4c9d2019ac670
BLAKE2b-256 a2f9912db3aba0a2203ea439331852d7ef2cac62dd48878293db4b676c9c1c1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for exact_cover_samples-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 28cdc58593fcf84c651a85276401c2610eff49379f2b7bc10b59da3420f35099
MD5 101508a1e34298050db5537d1301abcd
BLAKE2b-256 81a16b5dc367d6ea1ca51698b3f32bf53cbffcbfb2f8bd741b9257cd09b9cbbb

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