/* * 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 * . */ #include "solve.h" #include "sud.h" #include #include #include #include #include #include #define FNAME "puzzles" #define FSIZE 729000000U #define NSUD (FSIZE / NCELLS) int main(void) { int fd = open(FNAME, O_RDONLY); if (fd == -1) { fputs("Failed to open puzzles file\n", stderr); return EXIT_FAILURE; } char *buf = mmap(NULL, FSIZE, PROT_READ, MAP_PRIVATE, fd, 0); if (buf == MAP_FAILED) fputs("Failed to mmap() puzzle file\n", stderr); close(fd); struct sudoku sud; unsigned solved = 0; for (unsigned i = 0; i < NSUD; ++i) { if (!load(&sud, buf + (NCELLS * i))) { fputs("Failed to load sudoku\n", stderr); return EXIT_FAILURE; } if (solve(&sud) == -1) { fprintf(stderr, "Solver error on sudoku #%u\n", i); return EXIT_FAILURE; } if (filled(&sud)) ++solved; } double solved_pc = 1e2 * (double)solved / (double)NSUD; printf("Solved %u/%u (%.3lf%%)\n", solved, NSUD, solved_pc); return EXIT_SUCCESS; }