Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
x-o-referee.py solution in Creative category for Xs and Os Referee by s_m
def checkio(game_result: list) -> str:
X = 'XXX'
O = 'OOO'
l = game_result
horizontal = '-'.join(l)
vertical = ''.join(sum([list(x) + ['-'] for x in zip(l[0], l[1], l[2])], []))
diagonal_1 = ''.join([l[i][j] for i in range(len(l)) for j in range(len(l[i])) if i is j])
diagonal_2 = ''.join([l[::-1][i][j] for i in range(len(l)) for j in range(len(l[i])) if i is j])
res = '-'.join((horizontal, vertical, diagonal_1, diagonal_2))
return X in res and 'X' or O in res and 'O' or '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"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
April 18, 2018