-
Notifications
You must be signed in to change notification settings - Fork 15
/
wrapper.py
38 lines (33 loc) · 1.13 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
# 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
#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("sudokus_start.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 = Backtracking_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)