pub struct SumDifference { /* private fields */ }Expand description
When every term of equation A also appears in equation B, the remaining terms of B
sum to rhs(B) − rhs(A).
This is how a person combines overlapping sums: in Minesweeper, a 1 touching cells
{a, b} next to a 2 touching {a, b, c} makes c a mine (the “1-2 pattern”); in Kakuro
and Killer cages, a cage inside a row leaves the rest of the row a known total. Bounds on
each sum alone cannot see this. Only Relation::Equal constraints take part; the
derived equations are found once, at construction, and propagate like Linear.
The default name is “sum difference”; SumDifference::with_name sets a domain’s own
term.
§Examples
use constraint_search::{Domain, Domains, Linear, Relation, Rules, SumDifference};
let mut domains = Domains::<u16>::new();
let [a, b, c] = [(); 3].map(|()| domains.add(u16::range(2)));
let one = Linear::sum([a, b], Relation::Equal, 1);
let two = Linear::sum([a, b, c], Relation::Equal, 2);
let mut rules = Rules::new();
rules.add(SumDifference::new(2, [one, two]));
rules.solve(&mut domains, false)?;
assert_eq!(domains.value(c), Some(1));Implementations§
Trait Implementations§
Source§impl Clone for SumDifference
impl Clone for SumDifference
Source§impl Debug for SumDifference
impl Debug for SumDifference
impl Eq for SumDifference
Source§impl PartialEq for SumDifference
impl PartialEq for SumDifference
Source§impl<D: Domain> Rule<D> for SumDifference
impl<D: Domain> Rule<D> for SumDifference
Source§fn cost(&self) -> u32
fn cost(&self) -> u32
How hard the technique is to apply; rules run cheapest first. The scale is the
caller’s: grading reports the highest cost a solve needed.
Source§fn apply(&self, domains: &mut Domains<D>) -> Result<(), Inconsistent>
fn apply(&self, domains: &mut Domains<D>) -> Result<(), Inconsistent>
Applies the technique wherever it finds it, removing values from
domains. Read moreSource§fn assumes_unique(&self) -> bool
fn assumes_unique(&self) -> bool
Returns
true if the rule is sound only for puzzles with exactly one solution, such as
Sudoku’s unique rectangle. Rules skips these unless asked to assume uniqueness.impl StructuralPartialEq for SumDifference
Auto Trait Implementations§
impl Forget for SumDifference
impl Freeze for SumDifference
impl Move for SumDifference
impl RefUnwindSafe for SumDifference
impl Send for SumDifference
impl Sync for SumDifference
impl Unpin for SumDifference
impl UnsafeUnpin for SumDifference
impl UnwindSafe for SumDifference
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more