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 Mooshu
def checkio(game_result):
p = "".join(game_result)
n = list(p)
if n[0] == n[1] == n[2] != ".":
return n[0]
elif n[3] == n[4] == n[5] != ".":
return n[3]
elif n[6] == n[7] == n[8] != ".":
return n[6]
elif n[0] == n[4] == n[8] != ".":
return n[0]
elif n[2] == n[4] == n[6] != ".":
return n[2]
elif n[0] == n[3] == n[6] != ".":
return n[0]
elif n[1] == n[4] == n[7] != ".":
return n[1]
elif n[2] == n[5] == n[8] != ".":
return n[2]
else:
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"
Oct. 23, 2015