-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
31 lines (27 loc) · 1.11 KB
/
app.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
from flask import Flask, render_template, request, flash
from sudoku_solver.sudoku import sudoku_solver
app = Flask(__name__)
empty_grid = [['' for i in range(9)] for i in range(9)]
@app.route('/', methods=['GET', 'POST'])
def form():
if request.method == 'GET':
message1 = "Enter known numbers:"
return render_template('form.html', grid=empty_grid, message=message1)
elif request.method == 'POST':
grid = []
for i in range(1,82):
if request.form[str(i)] == '':
grid.append(0)
else:
grid.append(int(request.form[str(i)]))
grid = [grid[i:i+9] for i in range(0,81,9)]
if sudoku_solver(grid) == False:
message2 = "Please enter a valid grid!"
color1 = "pred"
return render_template('form.html', grid=empty_grid, message=message2, color=color1)
solved_grid = sudoku_solver(grid)
message3 = "Sudoku solved!"
color2 = "pgreen"
return render_template('form.html', grid=solved_grid, message=message3, color=color2)
if __name__ == "__main__":
app.run(debug=True)