Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
Data Structures | |
struct | sudoku |
Structure to hold the matrix and dimensions. More... | |
Functions | |
bool | OKrow (const struct sudoku *a, int x, int y, int v) |
Check if x ^th row is valid. More... | |
bool | OKcol (const struct sudoku *a, int x, int y, int v) |
Check if y ^th column is valid. More... | |
bool | OKbox (const struct sudoku *a, int x, int y, int v) |
Check if a 3x3 box is valid. More... | |
bool | OK (const struct sudoku *a, int x, int y, int v) |
Check if element v is valid to place at (x,y) location. More... | |
void | print (const struct sudoku *a) |
Print the matrix to stdout. More... | |
bool | get_next_unknown (const struct sudoku *a, int *x, int *y) |
Find and get the location for next empty cell. More... | |
bool | solve (struct sudoku *a) |
Function to solve a partially filled sudoku matrix. More... | |
bool get_next_unknown | ( | const struct sudoku * | a, |
int * | x, | ||
int * | y | ||
) |
Find and get the location for next empty cell.
[in] | a | pointer to sudoku instance |
[out] | x | pointer to row index of next unknown |
[out] | y | pointer to column index of next unknown |
true
if an empty location was found false
if no more empty locations found bool OK | ( | const struct sudoku * | a, |
int | x, | ||
int | y, | ||
int | v | ||
) |
Check if element v
is valid to place at (x,y) location.
a | sudoku to check |
x | row to place value |
y | column to place value |
v | value to check if it is valid |
true
if valid false
if in-valid bool OKbox | ( | const struct sudoku * | a, |
int | x, | ||
int | y, | ||
int | v | ||
) |
Check if a 3x3 box is valid.
a | matrix to check |
x | row index of the element to check |
y | column index of the element to check |
v | value to check if it repeats |
true
if valid false
if in-valid bool OKcol | ( | const struct sudoku * | a, |
int | x, | ||
int | y, | ||
int | v | ||
) |
Check if y
^th column is valid.
a | sudoku to check |
x | ignored row |
y | column to check |
v | value to check if it repeats |
true
if valid false
if in-valid bool OKrow | ( | const struct sudoku * | a, |
int | x, | ||
int | y, | ||
int | v | ||
) |
Check if x
^th row is valid.
a | sudoku to check |
x | row to check |
y | ignored column |
v | value to check if it repeats |
true
if valid false
if in-valid void print | ( | const struct sudoku * | a | ) |
Print the matrix to stdout.
[in] | a | array to print |
bool solve | ( | struct sudoku * | a | ) |
Function to solve a partially filled sudoku matrix.
For each unknown value (0), the function fills a possible value and calls the function again to check forvalid solution.
[in,out] | a | sudoku matrix to solve |
true
if solution found false
if no solution found