From f7d132397f2d76528635316c432f97e642558a6a Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Wed, 23 Nov 2022 22:18:07 +0000 Subject: [PATCH] Add filled() function as a faster alternative to check() --- sud.c | 11 +++++++++++ sud.h | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sud.c b/sud.c index 3d2bb12..364a9ba 100644 --- a/sud.c +++ b/sud.c @@ -241,3 +241,14 @@ enum check_res check(const struct sudoku *sud) /* If we've got this far, all is well. */ return SOLVED; } + +bool filled(const struct sudoku *sud) +{ + for (unsigned r = 0; r < NDIGITS; ++r) { + for (unsigned c = 0; c < NDIGITS; ++c) { + if (!sud->cells[r][c].det) + return false; + } + } + return true; +} diff --git a/sud.h b/sud.h index bdb8971..53c159f 100644 --- a/sud.h +++ b/sud.h @@ -71,6 +71,11 @@ void print(const struct sudoku *sud); * Determine whether the sudoku has been solved correctly, contains * invalid choices or is incomplete. */ -enum check_res check(const struct sudoku *sud); +enum check_res check(const struct sudoku *sud); + +/** + * Determine whether all the sudoku's cells have been determined. + */ +bool filled(const struct sudoku *sud); #endif