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 piotrekc88
def checkio(game_result):
#from left up corner to right down
if game_result[0][0]+game_result[1][1]+game_result[2][2]=="XXX": return "X"
if game_result[0][0]+game_result[1][1]+game_result[2][2]=="OOO": return "O"
#from right up corner to left down
if game_result[0][2]+game_result[1][1]+game_result[2][0]=="XXX": return "X"
if game_result[0][2]+game_result[1][1]+game_result[2][0]=="OOO": return "O"
for x in range(3):
#rows
if game_result[x] == "XXX": return "X"
if game_result[x] == "OOO": return "O"
#columns
if game_result[0][x]+game_result[1][x]+game_result[2][x]=="XXX": return "X"
if game_result[0][x]+game_result[1][x]+game_result[2][x]=="OOO": return "O"
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"
Dec. 20, 2015