Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Xs and Os Referee by Elena_Korljukova
from typing import List
def checkio(game_result: List[str]) -> str:
a = [(i,j) for i in range(3) for j in range(3)]
for p in "XO":
b = game_result + [''.join([i[j] for i in game_result]) for j in range(3)]
m = max(len([i[1] for i in a if game_result[i[0]][i[1]] == p and i[1] == i[0]]), len([i[1] for i in a if game_result[i[0]][i[1]] == p and i[1] == 2 - i[0]]))
if 3*p in b or m == 3:
return p
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!")
Aug. 6, 2020