# Struct sudoku::Sudoku
[−]
[src]

pub struct Sudoku(_);

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

## Methods

`impl Sudoku`

[src]

`fn generate_filled() -> Self`

[src]

Generate a random, solved sudoku Any valid sudoku can occur with equal probability

`fn generate_unique() -> Self`

[src]

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

`fn from_bytes_slice(bytes: &[u8]) -> Result<Sudoku, ()>`

[src]

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.

`fn from_bytes(bytes: [u8; 81]) -> Result<Sudoku, ()>`

[src]

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.

`fn from_str_line(s: &str) -> Result<Sudoku, LineFormatParseError>`

[src]

Reads a sudoku in the line format Stops parsing after the first sudoku

`fn from_str_block(s: &str) -> Result<Sudoku, BlockFormatParseError>`

[src]

Reads a sudoku in the block format with or without field delimiters Stops parsing after the first sudoku

`fn from_str_block_permissive(s: &str) -> Result<Sudoku, NotEnoughRows>`

[src]

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.

`fn solve(&mut self) -> bool`

[src]

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

`fn solve_one(self) -> Option<Sudoku>`

[src]

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.

`fn solve_unique(self) -> Option<Sudoku>`

[src]

Solve sudoku and return solution if solution is unique.

`fn count_at_most(self, limit: usize) -> usize`

[src]

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.

`fn is_uniquely_solvable(self) -> bool`

[src]

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.

`fn solve_at_most(self, limit: usize) -> Vec<Sudoku>`

[src]

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.

`fn is_solved(&self) -> bool`

[src]

Check whether the sudoku is solved.

`fn iter(&self) -> Map<Iter<'a, u8>, fn(_: &u8) -> Option<u8>>`

[src]

Returns an Iterator over sudoku, going from left to right, top to bottom

`fn to_bytes(self) -> [u8; 81]`

[src]

Returns a byte array for the sudoku. Empty cells are denoted by 0, clues by the numbers 1-9.

`fn to_str_line(&self) -> SudokuLine`

[src]

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(); // :SudokuLine println!("{}", line); let line_str: &str = &line; assert_eq!( "...5.............................................................................", line_str );

## Trait Implementations

`impl Copy for Sudoku`

[src]

`impl Clone for Sudoku`

[src]

`fn clone(&self) -> Sudoku`

[src]

Returns a copy of the value. Read more

`fn clone_from(&mut self, source: &Self)`

1.0.0[src]

Performs copy-assignment from `source`

. Read more

`impl PartialEq for Sudoku`

[src]

`fn eq(&self, other: &Sudoku) -> bool`

[src]

This method tests for `self`

and `other`

values to be equal, and is used by `==`

. Read more

`fn ne(&self, other: &Rhs) -> bool`

1.0.0[src]

This method tests for `!=`

.

`impl PartialOrd for Sudoku`

[src]

The ordering is lexicographical in the cells of the sudoku going from left to right, top to bottom

`fn partial_cmp(&self, other: &Self) -> Option<Ordering>`

[src]

This method returns an ordering between `self`

and `other`

values if one exists. Read more

`fn lt(&self, other: &Rhs) -> bool`

1.0.0[src]

This method tests less than (for `self`

and `other`

) and is used by the `<`

operator. Read more

`fn le(&self, other: &Rhs) -> bool`

1.0.0[src]

This method tests less than or equal to (for `self`

and `other`

) and is used by the `<=`

operator. Read more

`fn gt(&self, other: &Rhs) -> bool`

1.0.0[src]

This method tests greater than (for `self`

and `other`

) and is used by the `>`

operator. Read more

`fn ge(&self, other: &Rhs) -> bool`

1.0.0[src]

This method tests greater than or equal to (for `self`

and `other`

) and is used by the `>=`

operator. Read more

`impl Ord for Sudoku`

[src]

`fn cmp(&self, other: &Self) -> Ordering`

[src]

This method returns an `Ordering`

between `self`

and `other`

. Read more

`fn max(self, other: Self) -> Self`

1.22.0[src]

Compares and returns the maximum of two values. Read more

`fn min(self, other: Self) -> Self`

1.22.0[src]

Compares and returns the minimum of two values. Read more

`impl Hash for Sudoku`

[src]

`fn hash<H>(&self, state: &mut H) where`

H: Hasher,

[src]

H: Hasher,

Feeds this value into the given [`Hasher`

]. Read more

`fn hash_slice<H>(data: &[Self], state: &mut H) where`

H: Hasher,

1.3.0[src]

H: Hasher,

Feeds a slice of this type into the given [`Hasher`

]. Read more

`impl Eq for Sudoku`

[src]

`impl Debug for Sudoku`

[src]

`fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>`

[src]

Formats the value using the given formatter.