Struct puzzle_solver::Puzzle [] [src]

pub struct Puzzle { /* fields omitted */ }

The puzzle to be solved.

Methods

impl Puzzle
[src]

Allocate a new puzzle.

Examples

puzzle_solver::Puzzle::new();

Allocate a new puzzle variable, without inserting any candidates.

Examples

let mut puzzle = puzzle_solver::Puzzle::new();
puzzle.new_var();

Allocate a new puzzle variable, initialising it with potential candidates.

Examples

let mut send_more_money = puzzle_solver::Puzzle::new();
send_more_money.new_var_with_candidates(&[0,1,2,3,4,5,6,7,8,9]);

Allocate a 1d vector of puzzle variables, each initialised to have the same set of potential candidates.

Examples

let mut send_more_money = puzzle_solver::Puzzle::new();
send_more_money.new_vars_with_candidates_1d(8, &[0,1,2,3,4,5,6,7,8,9]);

Allocate a 2d array of puzzle variables, each initialised to have the same set of potential candidates.

Examples

let mut magic_square = puzzle_solver::Puzzle::new();
magic_square.new_vars_with_candidates_2d(3, 3, &[1,2,3,4,5,6,7,8,9]);

Set a variable to a known value.

This is useful when the variable is given as part of the problem. After this operation, any subsequent attempts to set the value will panic.

Examples

let mut magic_square = puzzle_solver::Puzzle::new();
let vars = magic_square.new_vars_with_candidates_2d(3, 3,
        &[1,2,3,4,5,6,7,8,9]);

magic_square.set_value(vars[1][1], 5);

Add candidates to a variable.

Examples

let mut send_more_money = puzzle_solver::Puzzle::new();
for _ in 0..9 {
    let var = send_more_money.new_var();
    send_more_money.insert_candidates(var, &[0,1,2,3,4,5,6,7,8,9]);
}

Remove candidates from a variable.

Examples

let mut send_more_money = puzzle_solver::Puzzle::new();
let vars = send_more_money.new_vars_with_candidates_1d(8,
        &[0,1,2,3,4,5,6,7,8,9]);

let s = vars[0];
let m = vars[4];
send_more_money.remove_candidates(s, &[0]);
send_more_money.remove_candidates(m, &[0]);

Set the variable's candidates to the intersection with the given list.

Examples

let mut send_more_money = puzzle_solver::Puzzle::new();
let vars = send_more_money.new_vars_with_candidates_1d(8,
        &[0,1,2,3,4,5,6,7,8,9]);

let m = vars[4];
send_more_money.intersect_candidates(m, &[0,1]);

Add a constraint to the puzzle solution.

Add an All Different constraint.

Examples

let mut send_more_money = puzzle_solver::Puzzle::new();
let vars = send_more_money.new_vars_with_candidates_1d(8,
        &[0,1,2,3,4,5,6,7,8,9]);

send_more_money.all_different(&vars);

Add an Equality constraint.

Examples

let mut magic_square = puzzle_solver::Puzzle::new();
let vars = magic_square.new_vars_with_candidates_2d(3, 3,
        &[1,2,3,4,5,6,7,8,9]);

magic_square.equals(vars[0][0] + vars[0][1] + vars[0][2], 15);

Add a Unify constraint.

Examples

let mut send_more_money = puzzle_solver::Puzzle::new();
let carry = send_more_money.new_vars_with_candidates_1d(4, &[0,1]);
let vars = send_more_money.new_vars_with_candidates_1d(8,
        &[0,1,2,3,4,5,6,7,8,9]);

let m = vars[4];
send_more_money.unify(m, carry[3]);

Find any solution to the given puzzle.

Examples

let mut puzzle = puzzle_solver::Puzzle::new();
puzzle.new_var_with_candidates(&[1,2]);
puzzle.new_var_with_candidates(&[3,4]);

let solution = puzzle.solve_any();
assert!(solution.is_some());

Find the solution to the given puzzle, verifying that it is unique.

Examples

let mut puzzle = puzzle_solver::Puzzle::new();
puzzle.new_var_with_candidates(&[1,2]);
puzzle.new_var_with_candidates(&[3,4]);

let solution = puzzle.solve_unique();
assert!(solution.is_none());

Find all solutions to the given puzzle.

Examples

let mut puzzle = puzzle_solver::Puzzle::new();
puzzle.new_var_with_candidates(&[1,2]);
puzzle.new_var_with_candidates(&[3,4]);

let solutions = puzzle.solve_all();
assert_eq!(solutions.len(), 4);

Take any obvious non-choices, using the constraints to eliminate candidates. Stops when it must start guessing. Primarily for testing.

Returns the intermediate puzzle search state, or None if a contradiction was found.

Get the number of guesses taken to solve the last puzzle.