-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (34 loc) · 874 Bytes
/
main.py
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
import os
import sys
import time
import sudoku
def timeit(f, title=None):
start = time.time()
result = f()
end = time.time()
if title:
print(title)
print("Time taken: %.02f" % (end - start))
return result
def test_solving_time():
def f1():
s = sudoku.Sudoku()
return sudoku.solve(s)
timeit(f1, "Backtracking")
def f2():
s = sudoku.Sudoku()
for i in range(9):
s[i] = i + 1
return sudoku.solve_sat(s)
print(timeit(f2, "SAT solving (with 9 assignments)"))
def recognize_image(path):
s = sudoku.Sudoku.fromimage(path)
print(s)
def main(path):
# test_solving_time()
recognize_image(path)
if __name__ == "__main__":
if len(sys.argv) != 2:
print(f"Usage: {os.path.basename(sys.argv[0])} SUDOKU_IMAGE")
else:
main(sys.argv[1])