| Crates.io | algoxcc |
| lib.rs | algoxcc |
| version | 0.1.2 |
| created_at | 2025-11-08 07:48:13.866512+00 |
| updated_at | 2025-11-08 11:43:44.525585+00 |
| description | A solver for an exact cover with colors problem |
| homepage | |
| repository | https://github.com/1Juhler-jdj/algoxcc |
| max_upload_size | |
| id | 1922611 |
| size | 109,538 |
A Rust implementation of Donald Knuthâs algorithm for solving an exact cover with colors problem using the Dancing Cells data structure.
More information about this crate can be found in the crate documentation.
The exact cover problem involves a set of items and a set of options, where each option is a subset of items. A solution to the problem is any subset of options in which all items are represented exactly once.
The generalized exact cover extends this with two types of items:
The exact cover with colors problem extends this by assigning colors to secondary items within options, allowing a secondary item to be covered by multiple options if they have the same color.
The inputs to the algorithm are defined in a Problem with:
Where an Option have:
Secondary items covered by an option are tuples with two elements as strings:
Where a blank color for a secondary item is regarded as a unique color.
With prerequisites:
To use algoxcc, first add this to your Cargo.toml:
[dependencies]
algoxcc = "0.1.1"
Next, add this to your crate:
use algoxcc::{Option, Problem, solve};
fn main() {
// ...
}
Solve a problem:
use algoxcc::{Option, Problem, solve};
// use new_validated constructors if we know input is valid
let problem = Problem::new_validated(
&vec!["a", "b", "c", "d"],
&vec![],
&vec![
Option::new_validated("o1", &vec!["b"], &vec![]),
Option::new_validated("o2", &vec!["a"], &vec![]),
Option::new_validated("o3", &vec!["b", "c"], &vec![]),
Option::new_validated("o4", &vec!["a", "c", "d"], &vec![]),
]
);
let result = solve(&problem, true);
assert!(result.is_ok());
let solutions = result.unwrap();
assert_eq!(1, solutions.count(), "Expect to find 1 solution");
let first = solutions.first().unwrap();
assert_eq!(2, first.len(), "Expect 2 options in solution");
assert_eq!("o1", first[0], "First option is o1");
assert_eq!("o4", first[1], "Second option is o4");