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()

will show all known problems

# you can also filter a bit
summary("pent")
->
the problems whose name contains 'pent' are:
===================== p3x20 ======================
size = (1236, 72),  8 solutions full_name=pentominos-3-20
===================== p4x15 ======================
size = (1696, 72),  1472 solutions full_name=pentominos-4-15

canonical representation

from exact_cover_samples import problems, canonical

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

p = problems["p8x8"]()
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["knuth2000"]()
# 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)

and so you can write a very decent test suite for your exact cover solver by simply iterating over the problems in problems and comparing the expected solutions with the computed ones.

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

Uploaded Source

Built Distribution

exact_cover_samples-0.0.6-py3-none-any.whl (313.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: exact_cover_samples-0.0.6.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.6.tar.gz
Algorithm Hash digest
SHA256 cdb1c1316c43393d17e86b8f218c83d4fb3b821e7c8748677bc7bbfc77e93228
MD5 a384d1612b5c0c425e81c52fa36ad419
BLAKE2b-256 dca02d3cf1725d97b8e56e080db1e178f22b37fd32e0111f9ef2b64054ab100f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for exact_cover_samples-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4e74b027a5b9a1a6864f1a19ddbc9491b086fb3a12777fce06ebc94213fb31d6
MD5 01340ad41e6f5a973cc421ad083116bd
BLAKE2b-256 1a010b5def78af108f80985ba0ce7c0285dc1a262ff7be77a60387b4039d6bf1

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