forked from 1989chenguo/CloudComputingLabs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
57 lines (51 loc) · 1.26 KB
/
main.cc
File metadata and controls
57 lines (51 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include "sudoku.h"
int64_t now()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000 + tv.tv_usec;
}
int main(int argc, char* argv[])
{
init_neighbors();
FILE* fp = fopen(argv[1], "r");
char puzzle[128];
int total_solved = 0;
int total = 0;
bool (*solve)(int) = solve_sudoku_basic;
// if (argv[2] != NULL)
// if (argv[2][0] == 'a')
// solve = solve_sudoku_min_arity;
// else if (argv[2][0] == 'c')
// solve = solve_sudoku_min_arity_cache;
// else if (argv[2][0] == 'd')
// solve = solve_sudoku_dancing_links;
int64_t start = now();
while (fgets(puzzle, sizeof puzzle, fp) != NULL) {
if (strlen(puzzle) >= N) {
++total;
input(puzzle);
//init_cache();
//if (solve_sudoku_min_arity_cache(0)) {
//if (solve_sudoku_min_arity(0))
//if (solve_sudoku_basic(0)) {
if (solve(0)) {
++total_solved;
if (!solved())
assert(0);
}
else {
printf("No: %s", puzzle);
}
}
}
int64_t end = now();
double sec = (end-start)/1000000.0;
printf("%f sec %f ms each %d\n", sec, 1000*sec/total, total_solved);
return 0;
}