Write program to evaluate results
This commit is contained in:
parent
08924e49d2
commit
516c9f5f55
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
|||||||
# Build files
|
# Build files
|
||||||
*.o
|
*.o
|
||||||
sudoku
|
sudoku
|
||||||
|
eval
|
||||||
|
|
||||||
# Test data
|
# Test data
|
||||||
sudoku.csv
|
sudoku.csv
|
||||||
|
13
Makefile
13
Makefile
@ -31,10 +31,14 @@ OBJ = $(SRC:.c=.o)
|
|||||||
sudoku: $(OBJ)
|
sudoku: $(OBJ)
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o $@
|
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o $@
|
||||||
|
|
||||||
clean:
|
eval: eval.o
|
||||||
rm -f sudoku $(OBJ)
|
$(CC) $(CFLAGS) $(LDFLAGS) eval.o -o $@
|
||||||
|
|
||||||
main.o: sud.h solve.h
|
clean:
|
||||||
|
rm -f sudoku *.o
|
||||||
|
|
||||||
|
eval.o: ds.h
|
||||||
|
main.o: sud.h solve.h ds.h
|
||||||
sud.o: sud.h
|
sud.o: sud.h
|
||||||
solve.o: solve.h
|
solve.o: solve.h
|
||||||
|
|
||||||
@ -47,7 +51,8 @@ solns: sudoku.csv
|
|||||||
results:
|
results:
|
||||||
dd if=/dev/zero of=$@ bs=1000 count=729000
|
dd if=/dev/zero of=$@ bs=1000 count=729000
|
||||||
|
|
||||||
run: sudoku puzzles results
|
run: sudoku eval puzzles solns results
|
||||||
time ./sudoku
|
time ./sudoku
|
||||||
|
./eval
|
||||||
|
|
||||||
.PHONY: clean run
|
.PHONY: clean run
|
||||||
|
24
ds.h
Normal file
24
ds.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DS_H
|
||||||
|
#define DS_H
|
||||||
|
|
||||||
|
#define NPUZZ 9000000U
|
||||||
|
|
||||||
|
#endif
|
65
eval.c
Normal file
65
eval.c
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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 correct = 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp(res, sol, NCELLS) == 0)
|
||||||
|
++correct;
|
||||||
|
}
|
||||||
|
|
||||||
|
double pc = 1e2 * (double)correct / (double)NPUZZ;
|
||||||
|
printf("%u/%u correct (%.2f%%)\n", correct, NPUZZ, pc);
|
||||||
|
|
||||||
|
fclose(rfp);
|
||||||
|
fclose(sfp);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
4
main.c
4
main.c
@ -16,6 +16,7 @@
|
|||||||
* <https://www.gnu.org/licenses/>.
|
* <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "ds.h"
|
||||||
#include "solve.h"
|
#include "solve.h"
|
||||||
#include "sud.h"
|
#include "sud.h"
|
||||||
|
|
||||||
@ -28,8 +29,7 @@
|
|||||||
|
|
||||||
#define IFNAME "puzzles"
|
#define IFNAME "puzzles"
|
||||||
#define OFNAME "results"
|
#define OFNAME "results"
|
||||||
#define NSUD 9000000U
|
#define FSIZE (NPUZZ * NCELLS)
|
||||||
#define FSIZE (NSUD * NCELLS)
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user