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 Elemenope
from typing import List
def checkio(game_result: List[str]) -> str:
gr, win = game_result, "" # shorter name, winner var
#check for winners
if gr[0][0] == gr[0][1] == gr[0][2] and gr[0][0] in "XO": # first row
return gr[0][0]
elif gr[1][0] == gr[1][1] == gr[1][2] and gr[1][0] in "XO": # second row
return gr[1][0]
elif gr[2][0] == gr[2][1] == gr[2][2] and gr[2][0] in "XO": # third row
return gr[2][0]
elif gr[0][0] == gr[1][0] == gr[2][0] and gr[0][0] in "XO": # first colomn
return gr[0][0]
elif gr[0][1] == gr[1][1] == gr[2][1] and gr[0][1] in "XO": # second colomn
return gr[0][1]
elif gr[0][2] == gr[1][2] == gr[2][2] and gr[2][2] in "XO": # third colomn
return gr[0][2]
elif gr[0][0] == gr[1][1] == gr[2][2] and gr[0][0] in "XO": # first diagonal
return gr[0][0]
elif gr[0][2] == gr[1][1] == gr[2][0] and gr[0][2] in "XO": # second diagonal
return gr[0][2]
else: # no winner
return "D"
if __name__ == '__main__':
print("Example:")
print(checkio(["...","XXX","OO."]))
#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!")
Dec. 23, 2018