sudoku: constraints: add solved predicate
This commit is contained in:
parent
36be2b2eb2
commit
06bba6ca68
|
@ -48,3 +48,21 @@ bool square_violation(const struct sudoku *grid, size_t i, size_t j) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool solved(const struct sudoku *grid) {
|
||||||
|
if (!grid)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 9; ++i) {
|
||||||
|
for (size_t j = 0; j < 9; ++j) {
|
||||||
|
if (line_violation(grid, i, j))
|
||||||
|
return false;
|
||||||
|
if (column_violation(grid, i, j))
|
||||||
|
return false;
|
||||||
|
if (square_violation(grid, i, j))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -10,4 +10,6 @@ bool line_violation(const struct sudoku *grid, size_t i, size_t j);
|
||||||
bool column_violation(const struct sudoku *grid, size_t i, size_t j);
|
bool column_violation(const struct sudoku *grid, size_t i, size_t j);
|
||||||
bool square_violation(const struct sudoku *grid, size_t i, size_t j);
|
bool square_violation(const struct sudoku *grid, size_t i, size_t j);
|
||||||
|
|
||||||
|
bool solved(const struct sudoku *grid);
|
||||||
|
|
||||||
#endif /* !CONSTRAINTS_H */
|
#endif /* !CONSTRAINTS_H */
|
||||||
|
|
Loading…
Reference in a new issue