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 Totorino
def checkio(game_result):
lines = game_result \
+ [[row[c] for row in game_result] for c in range(3)] \
+ [[game_result[a*x+b][x] for x in range(3)] for a, b in ((1, 0), (-1, 2))]
for line in lines:
r = all(l == 'X' for l in line) or all(l == 'O' for l in line)
if r:
return line[0]
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"
June 4, 2016
Comments: