Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Xs and Os Referee by madspark
# migrated from python 2.7
def checkio(game):
# rows
triples = [ set(row) for row in game ]
# columns
triples += [ set(game[i][j] for i in range(3)) for j in range(3) ]
# diagonals
triples.append(set(game[i][i] for i in range(3)))
triples.append(set(game[i][2-i] for i in range(3)))
# check
for player in 'XO':
if set(player) in triples:
return player
return 'D'
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio([
"X.O",
"XX.",
"XOO"]) == "X", "Xs wins"
assert checkio([
"OO.",
"XOX",
"XOX"]) == "O", "Os wins"
assert checkio([
"OOX",
"XXO",
"OXX"]) == "D", "Draw"
assert checkio([
"O.X",
"XX.",
"XOO"]) == "X", "Xs wins again"
Oct. 14, 2015