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 seednatural0331
from typing import List
def checkio(game_result: List[str]) -> str:
field = 3
players = ["O", "X"]
for player in players:
for i in range(field):
if all(game_result[i][j] == player for j in range(field)):
return player
for i in range(field):
if all(game_result[j][i] == player for j in range(field)):
return player
if all(game_result[i][i] == player for i in range(field)):
return player
if all(game_result[field-1-i][i] == player for i in range(field)):
return player
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!")
Nov. 30, 2019