From 119270c89b93f78fa2f3bc393a41ab147f8bf51d Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Wed, 23 Nov 2022 15:46:47 +0000 Subject: [PATCH] Apply rules to segments as well as rows and columns --- solve.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/solve.c b/solve.c index f762dd1..c8ec3b5 100644 --- a/solve.c +++ b/solve.c @@ -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)