pub struct Variable {
pub row: usize,
pub col: usize,
pub num: usize,
}Expand description
Represents a variable in the SAT encoding of a Sudoku puzzle.
A variable (row, col, num) is true if the cell at (row, col) contains num.
Rows, columns, and numbers are 1-indexed.
Fields§
§row: usizeThe row index (1-based).
col: usizeThe column index (1-based).
num: usizeThe number in the cell (1-based).
Implementations§
Source§impl Variable
impl Variable
Sourcepub const fn new(row: usize, col: usize, num: usize) -> Self
pub const fn new(row: usize, col: usize, num: usize) -> Self
Creates a new Variable.
§Arguments
row: 1-based row index.col: 1-based column index.num: 1-based number.
Sourcepub const fn encode(&self, size: Size) -> usize
pub const fn encode(&self, size: Size) -> usize
Encodes the variable into a unique positive integer for SAT solvers.
The encoding scheme maps (row, col, num) to a unique integer.
Assumes row, col, num are 1-indexed and within the board’s dimensions.
The resulting integer is also 1-indexed.
Formula: ((row - 1) * board_size^2) + ((col - 1) * board_size) + (num - 1) + 1
§Arguments
size: TheSizeof the Sudoku board.
Trait Implementations§
impl Copy for Variable
impl Eq for Variable
impl StructuralPartialEq for Variable
Auto Trait Implementations§
impl Freeze for Variable
impl RefUnwindSafe for Variable
impl Send for Variable
impl Sync for Variable
impl Unpin for Variable
impl UnwindSafe for Variable
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more