-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (27 loc) · 892 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
#!/usr/bin/env python3
from tkinter.filedialog import askopenfile, asksaveasfile
from os import getcwd
from sudoku import Sudoku
def main():
'''Driver for Sudoku solver'''
cwd = getcwd()
inputFile = askopenfile(mode='r', initialdir=cwd, title='Open Sudoku file')
puzzle = parseSudokuInput(inputFile)
sudoku = Sudoku(puzzle = puzzle)
output = 'Imported puzzle:\n'
output += str(sudoku)
sudoku.solve()
output += 'Solved puzzle:\n'
output += str(sudoku)
outputFile = asksaveasfile(mode='w+', initialdir=cwd, title='Save solution as')
outputFile.write(output)
def parseSudokuInput(inputFile):
result = []
line = inputFile.readline().strip()
while line:
for char in line.split(','):
result.append(int(char))
line = inputFile.readline()
return result
if __name__ == '__main__':
main()