From 7c6efa125e6692e30d131cba20d6e2025a373a80 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Thu, 24 Nov 2022 01:37:40 +0000 Subject: [PATCH] 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. --- sud.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/sud.c b/sud.c index 4d84a22..f14b20f 100644 --- a/sud.c +++ b/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. */