Apply rules to segments as well as rows and columns

This commit is contained in:
Camden Dixie O'Brien 2022-11-23 15:46:47 +00:00
parent d74b5410b6
commit 119270c89b

18
solve.c
View File

@ -120,7 +120,23 @@ int solve(struct sudoku *sud)
match = true;
}
/* TODO: Apply rules to each segment. */
/* Apply rules to each segment. */
for (i = 0; i < NDIGITS; ++i) {
for (j = 0; j < NDIGITS; ++j) {
r = 3 * (i / 3) + j / 3;
c = 3 * (i % 3) + j % 3;
group[j].row = r;
group[j].col = c;
group[j].state = &sud->cells[r][c];
}
res = apply_rules(sud, &group);
if (res == ERROR)
return -1;
else if (res == MATCH)
match = true;
}
/* Exit if no matches. */
if (!match)