|
ADS
Algorithms and Data Structures
|
The Sudoku (reality check of section 16.3 and exercise 16.7), of size \( n^2 \times n^2 \) with the numbers \( 1 , \ldots , n^2 \), \( n = 3 \) the classic one: the squares are filled in order, each with the numbers that check() allows, no equal number on its row, its column and its block of \( n \times n \), and the search backtracks when a square has none. More...
#include <cstddef>#include "ADS/Contract.h"#include <vector>#include "ADS/backtrack/impl/Sudoku.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Typedefs | |
| using | ADS::Grid = std::vector< std::vector< int > > |
| the squares, 0 empty | |
Functions | |
| bool | ADS::check (const Grid &S, std::size_t x, std::size_t y, int c) |
| whether \( c \) can be written in the square \( ( x , y ) \) of \( S \), i.e., it is not on its row, its column or its block | |
| bool | ADS::sudoku (Grid &S, std::size_t i=0) |
| fills the empty squares of \( S \) from the square number \( i \) on, in the order of the rows; true if it can | |
The Sudoku (reality check of section 16.3 and exercise 16.7), of size \( n^2 \times n^2 \) with the numbers \( 1 , \ldots , n^2 \), \( n = 3 \) the classic one: the squares are filled in order, each with the numbers that check() allows, no equal number on its row, its column and its block of \( n \times n \), and the search backtracks when a square has none.
The cost is a constant for \( n = 3 \), a huge one, and superpolynomial in \( n \). 0 marks an empty square.
The contracts [see Contract.h]: check() needs a square of the grid and a value in \( [ 1 , n^2 ] \); sudoku() a grid of \( n^2 \times n^2 \) squares with values in \( [ 0 , n^2 ] \), those given consistent, and the solution is checked too (both at level 3). The operations are defined in Sudoku.tpp.