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 tokiojapan55
from typing import List
def checkio(game_result: List[str]) -> str:
result = dict()
for r in range(3):
for c in range(3):
p = game_result[r][c]
if c == 0 and game_result[r][c + 1] == p and game_result[r][c + 2] == p:
result[p] = result.setdefault(p, 0) + 1
if r == 0 and game_result[r + 1][c] == p and game_result[r + 2][c] == p:
result[p] = result.setdefault(p, 0) + 1
if c == 0 and r == 0 and game_result[r + 1][c + 1] == p and game_result[r + 2][c + 2] == p:
result[p] = result.setdefault(p, 0) + 1
if c == 2 and r == 0 and game_result[r + 1][c - 1] == p and game_result[r + 2][c - 2] == p:
result[p] = result.setdefault(p, 0) + 1
if result.setdefault('X', 0) == result.setdefault('O', 0):
return "D"
elif result.setdefault('X', 0) > result.setdefault('O', 0):
return "X"
elif result.setdefault('O', 0) > result.setdefault('X', 0):
return "O"
else:
return "D"
June 22, 2020