Last active
December 28, 2015 02:19
-
-
Save chriszf/7427127 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 cross(A, B): | |
"Cross product of elements in A and elements in B." | |
return [a+b for a in A for b in B] | |
digits = '123456789' | |
rows = 'ABCDEFGHI' | |
cols = digits | |
squares = cross(rows, cols) | |
unitlist = ([cross(rows, c) for c in cols] + | |
[cross(r, cols) for r in rows] + | |
[cross(rs, cs) for rs in ('ABC','DEF','GHI') for cs in ('123','456','789')]) |
This file contains hidden or 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
units = {s: [u for u in unitlist if s in u] for s in squares} | |
peers = {s: {s1 for s1 in sum(units[s],[])}-{s} for s in squares} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment