Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
'chain' and 'zip' for rows and cols solution in Uncategorized category for Xs and Os Referee by Flying_Eye
from itertools import chain
def checkio(game_result):
for string in chain(game_result, zip(*game_result)):
if all(symb == string[0] for symb in string) and string[0] in {'X', 'O'}:
return string[0]
if all(game_result[i][i] == game_result[0][0]
for i in range(1, len(game_result))) and game_result[0][0] in {'X', 'O'}:
return game_result[0][0]
if all(game_result[i][-1 - i] == game_result[0][-1]
for i in range(1, len(game_result))) and game_result[0][-1] in {'X', 'O'}:
return game_result[0][-1]
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"
May 4, 2016
Comments: