Remove uneeded branches in update()
Now that the value and possible values are independent, it doesn't matter if we clobber the possible values of a cell that's been determined.
This commit is contained in:
parent
1a84d900f2
commit
7c6efa125e
21
sud.c
21
sud.c
@ -54,29 +54,20 @@ enum update_res update(struct sudoku *sud, unsigned r, unsigned c, unsigned val)
|
||||
unsigned tr, tc;
|
||||
const uint16_t clearmask = ~(1 << val);
|
||||
|
||||
/* Update possible values of cells in same column. */
|
||||
for (tr = 0; tr < NDIGITS; ++tr) {
|
||||
if (tr == r || DET(sud->cells[tr][c]))
|
||||
continue;
|
||||
sud->cells[tr][c] &= clearmask;
|
||||
}
|
||||
|
||||
/* Update possible values of cells in same row. */
|
||||
for (tc = 0; tc < NDIGITS; ++tc) {
|
||||
if (tc == c || DET(sud->cells[r][tc]))
|
||||
continue;
|
||||
for (tc = 0; tc < NDIGITS; ++tc)
|
||||
sud->cells[r][tc] &= clearmask;
|
||||
}
|
||||
|
||||
/* Update possible values of cells in same column. */
|
||||
for (tr = 0; tr < NDIGITS; ++tr)
|
||||
sud->cells[tr][c] &= clearmask;
|
||||
|
||||
/* Update possible values of cells in same segment. */
|
||||
const unsigned segr0 = SEGLEN * (r / SEGLEN);
|
||||
const unsigned segc0 = SEGLEN * (c / SEGLEN);
|
||||
for (tr = segr0; tr < segr0 + SEGLEN; ++tr) {
|
||||
for (tc = segc0; tc < segc0 + SEGLEN; ++tc) {
|
||||
if ((tr == r && tc == c) || DET(sud->cells[tr][tc]))
|
||||
continue;
|
||||
for (tc = segc0; tc < segc0 + SEGLEN; ++tc)
|
||||
sud->cells[tr][tc] &= clearmask;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the cell's value. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user