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 attilagerendi
from typing import List
def checkio(game_result: List[str]) -> str:
win = ((0,1,2), (3,4,5), (6,7,8), (0,3,6), (1,4,7), (2,5,8), (0,4,8), (2,4,6))
table = "".join(game_result)
win_x = any(table[a] == table[b] == table[c] == 'X' for a,b,c in win)
win_o = any(table[a] == table[b] == table[c] == 'O' for a,b,c in win)
if ((not win_x) and not(win_o)) or (win_x and win_o):
return 'D'
if win_x:
return 'X'
return 'O'
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!")
Jan. 17, 2021
Comments: