From 09a9f95740ddd43165c5d51d8a48d26edc34bcdb Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sat, 26 Nov 2022 02:21:16 +0000 Subject: [PATCH] Detect errors in evaluation program Errors here meaning where a value is filled in but not correct (as opposed to simply missing). --- eval.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/eval.c b/eval.c index fcad8f1..19cdd48 100644 --- a/eval.c +++ b/eval.c @@ -40,7 +40,7 @@ int main(void) return EXIT_FAILURE; } - unsigned correct = 0; + unsigned solved = 0, errors = 0; char res[NCELLS], sol[NCELLS]; for (unsigned i = 0; i < NPUZZ; ++i) { if (fread(&res, sizeof(char), NCELLS, rfp) != NCELLS) { @@ -52,12 +52,20 @@ int main(void) return EXIT_FAILURE; } - if (memcmp(res, sol, NCELLS) == 0) - ++correct; + bool allcells = true; + for (unsigned j = 0; j < NCELLS; ++j) { + if (res[j] != sol[j]) { + allcells = false; + if (res[j] != '0') + ++errors; + } + } + if (allcells) + ++solved; } - double pc = 1e2 * (double)correct / (double)NPUZZ; - printf("%u/%u correct (%.2f%%)\n", correct, NPUZZ, pc); + double pc = 1e2 * (double)solved / (double)NPUZZ; + printf("%u/%u (%.2f%%) solved, %u errors\n", solved, NPUZZ, pc, errors); fclose(rfp); fclose(sfp);