-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudoku.py
30 lines (24 loc) · 939 Bytes
/
sudoku.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
from csp import *
from datetime import datetime
with open("sudoku3.txt", "r") as file:
a = file.read().split("\n")
sudoku_inputs = ""
for i in range(9):
row = a[i].split(",")
for x in row:
sudoku_inputs += x
sudoku_inputs = sudoku_inputs.replace("0",".")
sudoku = Sudoku(sudoku_inputs)
sudoku.display(sudoku.infer_assignment())
print("\n## Solved with backtracking only ##\n")
before = datetime.now()
search = backtracking_search(sudoku)
after = datetime.now()
sudoku.display(sudoku.infer_assignment())
print("Running Time -->", (after - before).total_seconds())
print("\n## Solved with backtracking + mrv + lcv + ac3 ##\n")
before = datetime.now()
search = backtracking_search(sudoku, select_unassigned_variable=mrv, order_domain_values=lcv, inference=mac)
after = datetime.now()
sudoku.display(sudoku.infer_assignment())
print("Running Time -->", (after - before).total_seconds())