-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_solver.py
50 lines (44 loc) · 1.34 KB
/
main_solver.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
50
# main file for solver that interacts with user
import math
import csv
import time
from print_sudoku import *
from sudoku_solver import solve
input_file=input("Input the path to csv file : ") # input file must be in test_cases folder
use_dia=0
try:
use_dia=int(input("Do you want to use Diagonal constraint(Specify 1/0) : "))
except:
print("Invalid value setting to 0")
k=-1
rows=[]
# take input from csv file
try:
with open("test_cases/"+input_file,'r') as csvfile:
csvreader=csv.reader(csvfile)
for row in csvreader:
row_int=[]
for element in row:
row_int.append(int(element))
rows.append(row_int)
k=int(math.sqrt(len(rows)/2))
print("INPUT:")
print_main(rows,k) # print the input
except :
print("\nWrong csv file")
exit()
print("\nOUTPUT:")
#Checking input
for row in rows:
for ele in row:
if ele>k*k:
print("Wrong Input")
exit()
start_time=time.time()
result=solve(rows,k,True if use_dia==1 else False) # solve the sudoku
end_time=time.time()
if result :
print_main(result,k) # print the output
else:
print("None")
print("\nTime Taken: "+str(end_time-start_time)+"s")