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 igor.v.dudenko
from typing import List
def checkio(game_result: List[str]) -> str:
lines = game_result
num = range(0, 3)
for y in num:
lines.append(''.join(game_result[x][y] for x in num))
if y != 1:
lines.append(''.join(game_result[abs(y - x)][x] for x in num))
win = list(filter(lambda k: k.count(k[0]) == 3 and k[0] != '.', lines))
return win[0][0] if win else 'D'
if __name__ == '__main__':
print("Example:")
print(checkio(["X.O",
"XX.",
"XOO"]))
#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!")
Feb. 14, 2019