Detect errors in evaluation program

Errors here meaning where a value is filled in but not correct (as
opposed to simply missing).
This commit is contained in:
Camden Dixie O'Brien 2022-11-26 02:21:16 +00:00
parent d9c416ffe0
commit 09a9f95740

18
eval.c
View File

@ -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);