Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Compact solution solution in Clear category for Xs and Os Referee by Alexander_Antonov
from typing import List
def checkio(game_result: List[str]) -> str:
diags = [[game_result[i][i] for i in range(3)], [game_result[i][-i-1] for i in range(3)]]
for row in game_result + list(zip(*game_result)) + diags:
if len(set(row)) == 1 and '.' not in row[0]:
return row[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!")
Feb. 23, 2020