The main structure exposing all the functionality of the library
Sudokus can be parsed in either the line format or the block format
line format:
..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3.. optional comment
block format:
__3_2_6__ optional comment
9__3_5__1 another comment
__18_64__
__81_29__
7_______8
__67_82__
__26_95__
8__2_3__9
__5_1_3__
alternatively also with field delimiters
__3|_2_|6__ optional comment
9__|3_5|__1 another comment
__1|8_6|4__
---+---+--- comment: "-----------", i.e. '-' 11 times is also allowed
__8|1_2|9__ but has to be consistent
7__|___|__8
__6|7_8|2__
---+---+---
__2|6_9|5__
8__|2_3|__9
__5|_1_|3__
'_'
, '.'
and '0'
are accepted interchangeably as unfilled cells
Generate a random, solved sudoku
Generate a random, uniquely solvable sudoku
The puzzles are minimal in that no cell can be removed without losing uniquess of solution
Most puzzles generated by this are easy
Generate a random, uniqely solvable sudoku
that has the same solution as the given sudoku
by removing the contents of some of its cells.
The puzzles are minimal in that no cell can be removed without losing uniquess of solution.
Most puzzles generated by this from solved sudokus are easy.
If the source sudoku
is invalid or has multiple solutions, it will be returned as is.
Creates a sudoku from a byte slice.
All numbers must be below 10. Empty cells are denoted by 0, clues by the numbers 1-9.
The slice must be of length 81.
Creates a sudoku from a byte array.
All numbers must be below 10. Empty cells are denoted by 0, clues by the numbers 1-9.
Reads a sudoku in the line format
Stops parsing after the first sudoku
Reads a sudoku in the block format with or without field delimiters
Stops parsing after the first sudoku
Reads a sudoku in a variety of block formats, applying few constraints.
'_', '.' and '0' are treated as empty cells. '1' to '9' as clues. Each line needs to have 9 valid cells.
Lines that don't contain 9 valid entries are ignored.
Stops parsing after the first sudoku. Due to the lax format rules, the only failure that can occur
is that there are not enough rows.
Try to find a solution to the sudoku and fill it in. Return true if a solution was found.
This is a convenience interface. Use one of the other solver methods for better error handling
Find a solution to the sudoku. If multiple solutions exist, it will not find them and just stop at the first.
Return None
if no solution exists.
Solve sudoku and return solution if solution is unique.
Counts number of solutions to sudoku up to limit
This solves the sudoku but does not return the solutions which allows for slightly faster execution.
Checks whether sudoku has one and only one solution.
This solves the sudoku but does not return the solution which allows for slightly faster execution.
Solve sudoku and return the first limit
solutions it finds. If less solutions exist, return only those. Return None
if no solution exists.
No specific ordering of solutions is promised. It can change across versions.
Counts number of solutions to sudoku up to limit
and writes any solution found into target
up to its capacity. Additional solutions will be counted but not saved.
No specific ordering of solutions is promised. It can change across versions.
This is primarily meant for C FFI.
Check whether the sudoku is solved.
Returns number of filled cells
Perform various transformations that create a different but equivalent sudoku.
The transformations preserve the sudoku's validity and the amount of solutions
as well a the applicability of solution strategies.
Shuffling can be used to quickly generate sudokus of the same difficulty as a given sudoku.
Transformations that are applied:
- Relabel numbers, e.g. swap all 1s and all 3s (9! permutations)
- Permute rows within their band and columns within their stack (3!3 * 2 permutations)
- Permute stacks and bands (3!2 permutations)
- Transpose the board, i.e. mirror it along the diagonal (2 permutations)
The remaining rotations as well as mirrorings can be produced by a combination with the other transformations
This results in a total of up to 2 * 9! * 3!8 = 1,218,998,108,160 permutations
Less permutations exists if the sudoku is symmetrical in respect to some combinations of the transformations
The vast majority of sudokus do not have any such symmetries (automorphisms). The highest number of automorphisms
a sudoku can have is 648 and ~99.99% of all non-equivalent sudokus have only 1, the identity transformation.
Returns an Iterator over sudoku, going from left to right, top to bottom
Returns a byte array for the sudoku.
Empty cells are denoted by 0, clues by the numbers 1-9.
Returns a representation of the sudoku in line format that can be printed
and which derefs into a &str
use sudoku::Sudoku;
let mut grid = [0; 81];
grid[3] = 5;
let sudoku = Sudoku::from_bytes(grid).unwrap();
let line = sudoku.to_str_line();
println!("{}", line);
let line_str: &str = &line;
assert_eq!(
"...5.............................................................................",
line_str
);
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Performs copy-assignment from source
. Read more
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the minimum of two values. Read more
The ordering is lexicographical in the cells of the sudoku
going from left to right, top to bottom
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given [Hasher
]. Read more
Feeds a slice of this type into the given [Hasher
]. Read more
Converts the given value to a String
. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more