Created
March 16, 2012 00:33
-
-
Save enaeseth/2047881 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
import json | |
import re # Now I have two problems! | |
def munge(board): | |
num_rows = len(board) | |
rows = [''.join(row) for row in board] | |
cols = [''.join(col) for col in zip(*board)] | |
diag1 = [''.join(diag) for diag in | |
zip(*[' ' * offset + ''.join(row) for row, offset in | |
zip(board, range(num_rows))])] | |
diag2 = [''.join(diag) for diag in | |
zip(*[' ' * offset + ''.join(row) for row, offset in | |
zip(board, range(num_rows, -1, -1))])] | |
return '|'.join(['|'.join(x) for x in (rows, cols, diag1, diag2)]) | |
def main(blob): | |
board = json.loads(blob) | |
possibilities = munge(board) | |
match = re.search('(X{4}|O{4})', possibilities) | |
print "Winner: %s" % (match.group()[0] if match else "None") | |
if __name__ == '__main__': | |
import sys | |
main(sys.stdin.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment