Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
seems ok :) solution in Clear category for Xs and Os Referee by leshchenko
from typing import List
from collections import Counter
def checkio(game_result: List[str]) -> str:
def check_seq(seq):
"""Return who wins in a sequence of 3 symbols."""
contents = list(set(seq))
if len(contents) == 1 and contents[0] in ["X", "O"]:
return contents[0]
return "D"
# check horizontals
checks = [check_seq(line) for line in game_result]
# check verticals
checks += [check_seq(line) for line in list(zip(*game_result))]
# check diags
diags = [
[game_result[i][func(i)] for i in range(3)]
for func in (lambda x: x, lambda x: 2 - x)
]
checks += [check_seq(line) for line in diags]
# calc final results
counter = Counter(checks)
del counter["D"]
return max(counter, key=lambda x: counter[x]) if counter else "D"
Aug. 19, 2021
Comments: