Errors here meaning where a value is filled in but not correct (as opposed to simply missing).
74 lines
1.9 KiB
C
74 lines
1.9 KiB
C
/*
|
|
* Copyright (C) 2022 Camden Dixie O'Brien
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public
|
|
* License along with this program. If not, see
|
|
* <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "ds.h"
|
|
#include "sud.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define RESNAME "results"
|
|
#define SOLNAME "solns"
|
|
|
|
int main(void)
|
|
{
|
|
FILE *rfp = fopen(RESNAME, "rb");
|
|
if (!rfp) {
|
|
fputs("Failed to open results file\n", stderr);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
FILE *sfp = fopen(SOLNAME, "rb");
|
|
if (!sfp) {
|
|
fputs("Failed to open solutions file\n", stderr);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
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) {
|
|
fprintf(stderr, "Failed to read result #%u\n", i);
|
|
return EXIT_FAILURE;
|
|
}
|
|
if (fread(&sol, sizeof(char), NCELLS, sfp) != NCELLS) {
|
|
fprintf(stderr, "Failed to read result #%u\n", i);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
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)solved / (double)NPUZZ;
|
|
printf("%u/%u (%.2f%%) solved, %u errors\n", solved, NPUZZ, pc, errors);
|
|
|
|
fclose(rfp);
|
|
fclose(sfp);
|
|
return EXIT_SUCCESS;
|
|
}
|