pub struct Sudoku { /* private fields */ }
Implementations§
Source§impl Sudoku
impl Sudoku
Sourcepub fn new(n: usize) -> (Self, Self)
pub fn new(n: usize) -> (Self, Self)
Populates a Sudoku board with n hints.
Returns (unsolved sudoku, solved sudoku)
.
Sourcepub fn decimate(&mut self, n: usize) -> Result<(), String>
pub fn decimate(&mut self, n: usize) -> Result<(), String>
Removes elements from a filled sudoku until there
are n
elements left, while having only 1 solution.
Sourcepub fn solve(&mut self, r: usize, c: usize) -> i32
pub fn solve(&mut self, r: usize, c: usize) -> i32
Returns the number of different solutions of a given Sudoku
call this function with sudoku.solve(0, 0)
.
Sourcepub fn fill(&mut self, r: usize, c: usize) -> Result<(), ()>
pub fn fill(&mut self, r: usize, c: usize) -> Result<(), ()>
Fills an empty sudoku board.
Row and col are the first empty index.
Call this function with sudoku.fill(0, 0)
to fill an empty board completely.
Sourcepub fn check_all(&self) -> bool
pub fn check_all(&self) -> bool
Checks all rows, cols and squares by checking these indexes.
X** *** ***
*** X** ***
*** *** X**
*X* *** ***
*** *X* *** the Xs get checked
*** *** *X*
**X *** ***
*** **X ***
*** *** **X
Sourcepub fn check(&self, r: usize, c: usize) -> bool
pub fn check(&self, r: usize, c: usize) -> bool
Returns true
if the row, column and square of the indices have no duplicate SudokuValue.
Sourcepub fn count(&self, val: SudokuValue) -> usize
pub fn count(&self, val: SudokuValue) -> usize
Returns how often the SudokuValue is on the board.
Sourcepub fn get_column(&self, c: usize) -> Option<[&SudokuValue; 9]>
pub fn get_column(&self, c: usize) -> Option<[&SudokuValue; 9]>
Returns the specified column.
Sourcepub fn get_square(&self, r: usize, c: usize) -> Option<[&SudokuValue; 9]>
pub fn get_square(&self, r: usize, c: usize) -> Option<[&SudokuValue; 9]>
Returns the square in which the indices lie.
Sourcepub fn get(&self, r: usize, c: usize) -> Option<&SudokuValue>
pub fn get(&self, r: usize, c: usize) -> Option<&SudokuValue>
Returns the SudokuValue at the specified indices.
Sourcepub fn set(&mut self, r: usize, c: usize, val: SudokuValue)
pub fn set(&mut self, r: usize, c: usize, val: SudokuValue)
Sets the value at the specified indices.
Trait Implementations§
Source§impl Ord for Sudoku
impl Ord for Sudoku
Source§impl PartialOrd for Sudoku
impl PartialOrd for Sudoku
impl Copy for Sudoku
impl Eq for Sudoku
impl StructuralPartialEq for Sudoku
Auto Trait Implementations§
impl Freeze for Sudoku
impl RefUnwindSafe for Sudoku
impl Send for Sudoku
impl Sync for Sudoku
impl Unpin for Sudoku
impl UnwindSafe for Sudoku
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
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>
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>
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