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 pwelo
def checkio(game_result):
gr = "".join(game_result)
result = [gr[:3], gr[3:6], gr[6:], # row
gr[::3], gr[1::3], gr[2::3], # col
gr[::4], gr[2:7:2]] # diag
for r in result:
if r.count("X") == 3: return "X"
if r.count("O") == 3: 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"
Feb. 22, 2015