Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Xs and Os Referee by cbrunet
def checkio(game_result):
game_result += [''.join(x) for x in zip(*game_result)]
game_result.append(''.join(game_result[i][i] for i in range(3)))
game_result.append(''.join(game_result[i][2-i] for i in range(3)))
if 'XXX' in game_result:
return 'X'
elif 'OOO' in game_result:
return 'O'
else:
return 'D'
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio([
"X.O",
"XX.",
"XOO"]) == "X", "Xs wins"
assert checkio([
"OO.",
"XOX",
"XOX"]) == "O", "Os wins"
assert checkio([
"OOX",
"XXO",
"OXX"]) == "D", "Draw"
Sept. 17, 2013