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
# Sudoku solver for Udacity CS258. | |
def get_groups(): | |
q = lambda f:[[f(i,j) for j in range(9)] for i in range(9)] | |
return q(lambda i,j:(i,j)) + q(lambda i,j:(j,i)) + q(lambda i,j:(i/3*3+j/3,i%3*3+j%3)) | |
# I think this is more readable than the one-liner: | |
# >> return [l for i in range(9) for l in zip(*[[(i,j),(j,i),(i/3*3+j/3,i%3*3+j%3)] for j in range(9)])] | |
def check_sudoku(grid): | |
# Check to see if grid is a list with 9 elements |
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 get_groups(): | |
q = lambda f:[[f(i,j) for j in range(9)] for i in range(9)] | |
return q(lambda i,j:(i,j)) + q(lambda i,j:(j,i)) + q(lambda i,j:(i/3*3+j/3,i%3*3+j%3)) | |
# I think this is more readable than the one-liner: | |
# >> return [l for i in range(9) for l in zip(*[[(i,j),(j,i),(i/3*3+j/3,i%3*3+j%3)] for j in range(9)])] | |
def check_sudoku(grid): | |
# Check to see if grid is a list with 9 elements | |
if ((not type(grid) is list) or (len(grid) != 9)): return None |