Created
May 7, 2015 07:06
-
-
Save poliarush/4c257caafcf7addb7b4f to your computer and use it in GitHub Desktop.
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
import math | |
def convert_blocks_to_lists(list): | |
block_length = int(math.sqrt(len(list))) | |
squares = [] | |
for i in range(0,len(list),block_length): | |
for j in range(0,len(list),block_length): | |
squares.append([item for x in range (i,i+block_length) for item in list[x][j:j+block_length]]) | |
return squares | |
def main(sudoku_list): | |
length_of_sudoku_board = len(sudoku_list[0]) | |
check_sum = sum([i for i in range(1,length_of_sudoku_board+1)]) | |
blocks = convert_blocks_to_lists(sudoku_list) | |
for i in range(length_of_sudoku_board): | |
if sum(sudoku_list[i]) != check_sum: | |
return False | |
elif sum([item[i] for item in sudoku_list]) != check_sum: | |
return False | |
elif sum(blocks[i]) != check_sum: | |
return False | |
return True | |
if __name__ == "__main__": | |
sudoku = [ | |
[1,2,3,4], | |
[3,4,2,1], | |
[4,3,1,2], | |
[2,1,4,3] | |
] | |
print main(sudoku) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment