Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Should be easy to understand solution in Clear category for Xs and Os Referee by Selindian
from typing import List
def checkio(game_result: List[str]) -> str:
# rows
for a, b, c in game_result:
if a == b == c != '.': return a
# columns
for a, b, c in zip(*game_result):
if a == b == c != '.': return a
# diagonals
if game_result[0][0] == game_result[1][1] == game_result[2][2] != '.': return game_result[1][1]
if game_result[0][2] == game_result[1][1] == game_result[2][0] != '.': return game_result[1][1]
# draw
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", "X wins"
assert checkio(["OO.", "XOX", "XOX"]) == "O", "O wins"
assert checkio(["OOX", "XXO", "OXX"]) == "D", "Draw"
assert checkio(["O.X", "XX.", "XOO"]) == "X", "X wins again"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
March 28, 2022
Comments: