-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudoku_validator.py
44 lines (35 loc) · 1.07 KB
/
sudoku_validator.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
def notInRow(arr, row):
st = set()
for i in range(0, 9):
if arr[row][i] in st:
return False
if arr[row][i] != 0:
st.add(arr[row][i])
return True
def notInCol(arr, col):
st = set()
for i in range(0, 9):
if arr[i][col] in st:
return False
if arr[i][col] != 0:
st.add(arr[i][col])
return True
def notInBox(arr, startRow, startCol):
st = set()
for row in range(0, 3):
for col in range(0, 3):
curr = arr[row + startRow][col + startCol]
if curr in st:
return False
if curr != 0:
st.add(curr)
return True
def isValid(arr, row, col):
return (notInRow(arr, row) and notInCol(arr, col) and
notInBox(arr, row - row % 3, col - col % 3))
def isValidConfig(arr):
for i in range(0, 9):
for j in range(0, 9):
if not isValid(arr, i, j):
return False
return True