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.3.tar.gz
(92.6 kB
view details)
Built Distribution
File details
Details for the file exact_cover_samples-0.0.3.tar.gz
.
File metadata
- Download URL: exact_cover_samples-0.0.3.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19207fecec60d852f6dea1e3b0bc1afce697d9e3ae21033e5eff01323f83f1ef |
|
MD5 | 8da248db8d516619553cdd4627d27abc |
|
BLAKE2b-256 | 3fedded09d314fb475b0576fa3dda41e5907853fccb3fba8cfb0700708921709 |
File details
Details for the file exact_cover_samples-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: exact_cover_samples-0.0.3-py3-none-any.whl
- Upload date:
- Size: 90.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 893b22f4d70f323bc2724e501ce1f3bf848450a05ea12f4e3f479507fe7b7151 |
|
MD5 | 3934d8090a14cc6232b21b826b04d930 |
|
BLAKE2b-256 | 6b1bfdb46b856201e5e95532bccca1702752306a2abca51f4bdc4080290ff95b |