Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear solution solution in Clear category for Xs and Os Referee by Goodester
from typing import List
def checkio(game_result: List[str]) -> str:
if check_for_consecutives(game_result, 'X'):
return 'X'
elif check_for_consecutives(game_result, 'O'):
return 'O'
else:
return 'D'
def check_for_consecutives(table, token):
return any(all_equal_to(row, token) for row in (*table, *get_cols(table), *get_diagonals(table)))
def get_diagonals(table):
return ''.join([row[i] for i, row in enumerate(table)]), \
''.join([row[len(row) - i - 1] for i, row in enumerate(table)])
def get_cols(table):
return tuple(''.join([table[c_i][r_i] for c_i, c in enumerate(row)]) for r_i, row in enumerate(table))
def all_equal_to(it, token):
return all([el == token for el in it])
Aug. 23, 2020