Last active
October 5, 2019 02:11
-
-
Save sheldonrobinson/52982f13177bebdede7ee98a0655f66d to your computer and use it in GitHub Desktop.
CodeSignal Solution for sudoku2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sudoku2(grid): | |
# test row | |
tab = [[False for col in range(9)] for row in range(9)] | |
cols = [[False for col in range(9)] for row in range(9)] | |
rows = [[False for col in range(9)] for row in range(9)] | |
for r in range(9): | |
for c in range(9): | |
if grid[r][c] == ".": | |
continue | |
v = int(grid[r][c])-1 | |
if rows[r][v]: | |
return False | |
else: | |
rows[r][v] = 1 | |
if cols[c][v]: | |
return False | |
else: | |
cols[c][v] = 1 | |
a = ((r//3)*3) + (c//3) | |
if tab[a][v]: | |
return False | |
else: | |
tab[a][v] = 1 | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
break => continue