Last active
December 25, 2015 10:58
-
-
Save kojiromike/6965042 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
#!/usr/bin/env python | |
correct = [[[1,2,3], | |
[2,3,1], | |
[3,1,2]], | |
[[1, 2, 3, 4], | |
[2, 3, 4, 1], | |
[4, 1, 2, 3], | |
[3, 4, 1, 2]]] | |
incorrect = [[[1, 2, 3, 4], | |
[2, 3, 1, 3], | |
[3, 1, 2, 3], | |
[4, 4, 4, 4]], | |
[[1, 2, 3, 4], | |
[2, 3, 1, 4], | |
[4, 1, 2, 3], | |
[3, 4, 1, 2]], | |
[[1, 2, 3, 4, 5], | |
[2, 3, 1, 5, 6], | |
[4, 5, 2, 1, 3], | |
[3, 4, 5, 2, 1], | |
[5, 6, 4, 3, 2]], | |
[['a', 'b', 'c'], | |
['b', 'c', 'a'], | |
['c', 'a', 'b']], | |
[[1, 1.5], | |
[1.5, 1]], | |
[[-2, -1, 0], | |
[-1, 0, -2], | |
[ 0, -2, -1]]] | |
check_sudoku_square = lambda sq: all([len(set(map(len, sq))) == 1, # Every row has the same number of elements. | |
len(sq) == len(sq[0])] # The matrix is a square. | |
+ map(lambda row: set(row) == set(range(1, len(sq) + 1)), | |
sq + zip(*sq)), # Each row and col has all 1..N elements | |
) | |
for sq in correct: | |
try: | |
assert check_sudoku_square(sq), sq | |
except: | |
print sq | |
raise | |
for sq in incorrect: | |
try: | |
assert not check_sudoku_square(sq), sq | |
except: | |
print sq | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment