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 polly
def checkio(game_result):
res=game_result.copy()
res+=["".join(str) for str in (zip(game_result[0],game_result[1],game_result[2]))]
res.append(''.join([game_result[i][i] for i in range(3)]))
res.append(''.join([game_result[i][2-i] for i in range(3)]))
win='D'
for str in res:
if str.count('X')==3:
win='X'
break
if str.count('O')==3:
win='O'
break
return win
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"
Jan. 15, 2015
Comments: