sudoku: constraints: add solved predicate

This commit is contained in:
Bruno BELANYI 2020-12-21 21:00:42 +01:00
parent 36be2b2eb2
commit 06bba6ca68
2 changed files with 20 additions and 0 deletions

View file

@ -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;
}

View file

@ -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 */