Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Xs and Os Referee by Gravizapa
from typing import List
def checkio(game_result: List[str]) -> str:
g = "".join(game_result)
win_lst = ["012", "345", "678", "036", "147", "258", "048", "246"]
for _ in win_lst:
temp = list(map(int, list(_)))
if g[temp[0]] == g[temp[1]] and g[temp[1]] == g[temp[2]]:
if g[temp[0]] == "O":
return "O"
elif g[temp[0]] == "X":
return "X"
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!")
Dec. 7, 2020