forked from SrinidhiRaghavan/AI-Sudoku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapper.py
39 lines (34 loc) · 1.16 KB
/
wrapper.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
# THE WRAPPER FUNCTION WHICH SOLVES ALL THE SUDOKU PROBLEMS IN THE INPUT FILE USING BACKTRACKING AND WRITES THE OUTPUT TO THE OUTPUT FILE
import sys #For getting the values from command line
from CSP import csp
#from Backtrack import *
import time
from MRVDH6 import *
#THE MAIN FUNCTION GOES HERE
if __name__ == "__main__":
'''
The function takes arguments from commandline
Argument 1 - Python file name
Argument 2 - Input String Showing the Sudoku
'''
array = []
with open("data\sudokus_start2.txt", "r") as ins:
for line in ins:
array.append(line)
ins.close()
i = 0
boardno = 0
start = time.time()
f = open("output.txt", "w")
for grid in array:
startpuzle = time.time()
boardno = boardno + 1
sudoku = csp(grid=grid)
solved = BacktrackingMRVDH_Search(sudoku)
print ("The board-", boardno, " takes ", time.time() - startpuzle, " seconds")
if solved!="FAILURE":
f.write(write(solved)+"\n")
i = i + 1
f.close()
print ("Number of problems solved is: ", i)
print ("Time taken to solve the puzzles is: ", time.time()-start)