Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Xs and Os Referee by yanhua.dev
from typing import List
def checkio(game_result: List[str]) -> str:
horizontal_rows = [list(game_result[i]) for i in range(3)]
vertial_cols = [[game_result[0][i],game_result[1][i],game_result[2][i]] for i in range(3)]
diagonal_rows = [[game_result[i][i] for i in range(3)],[game_result[i][2-i] for i in range(3)]]
for c in horizontal_rows + vertial_cols+diagonal_rows:
if c.count(c[0]) == len(c) and not c[0] == '.':
return c[0]
return "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!")
June 29, 2018