From 5aea129dc9cfb37c1fcb59179a850b802f6a5461 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Wed, 23 Nov 2022 15:50:20 +0000 Subject: [PATCH] Only apply rules to rows It goes faster this way. --- solve.c | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/solve.c b/solve.c index c8ec3b5..cdc7b22 100644 --- a/solve.c +++ b/solve.c @@ -83,7 +83,7 @@ static enum apply_res apply_rules(struct sudoku *sud, cellgroup *group) int solve(struct sudoku *sud) { cellgroup group = { 0 }; - unsigned r, c, i, j, n; + unsigned r, c, n; bool match; enum apply_res res; @@ -105,39 +105,6 @@ int solve(struct sudoku *sud) match = true; } - /* Apply rules to each column. */ - for (c = 0; c < NDIGITS; ++c) { - for (r = 0; r < NDIGITS; ++r) { - group[r].row = r; - group[r].col = c; - group[r].state = &sud->cells[r][c]; - } - - res = apply_rules(sud, &group); - if (res == ERROR) - return -1; - else if (res == MATCH) - match = true; - } - - /* 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) return n;