check solution
This commit is contained in:
parent
97358e6797
commit
86ea672173
34
sudoku.c
34
sudoku.c
@ -231,6 +231,38 @@ void setValue(int q, int f, int val) {
|
||||
//printDumpSudoku();
|
||||
}
|
||||
|
||||
bool checkSolution() {
|
||||
bool foundError = false;
|
||||
|
||||
for (int val = 1; val <= 9; val++) {
|
||||
// check for val every quadrat
|
||||
for (int q = 0; q < 9; q++) {
|
||||
if (!isInQuadrat(q, val)) {
|
||||
foundError = true;
|
||||
fprintf(stderr, "Value %d not found in Q %d\n", val, q);
|
||||
}
|
||||
}
|
||||
|
||||
// check for val in every row
|
||||
for (int r = 0; r < 9; r++) {
|
||||
if (!isInRow(r, val)) {
|
||||
foundError = true;
|
||||
fprintf(stderr, "Value %d not found in row %d\n", val, r);
|
||||
}
|
||||
}
|
||||
|
||||
// check for val in every col
|
||||
for (int c = 0; c < 9; c++) {
|
||||
if (!isInCol(c, val)) {
|
||||
foundError = true;
|
||||
fprintf(stderr, "Value %d not found in col %d\n", val, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !foundError;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printDumpSudoku();
|
||||
bool somethingChanged;
|
||||
@ -302,4 +334,6 @@ int main() {
|
||||
} while (somethingChanged);
|
||||
|
||||
printDumpSudoku();
|
||||
|
||||
checkSolution();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user