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 Bartosz_M
def checkio(game_result):
game_result = ''.join(game_result)
for i in range((len(game_result)) - 6):
if game_result[i] == game_result[i + 3] == game_result[i + 6]:
if game_result[i] in "XO":
return game_result[i]
for i in range((len(game_result)) - 2):
if (game_result[i] == game_result[i + 1] == game_result[i + 2]) and i%3==0:
if game_result[i] in "XO":
return game_result[i]
if game_result[0] == game_result[4] == game_result[8]:
if game_result[0] in "XO":
return game_result[0]
if game_result[2] == game_result[4] == game_result[6]:
if game_result[2] in "XO":
return game_result[2]
return "D"
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(["O..","XOX","..O"]) == "O", "Os 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"
Nov. 22, 2016