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 BartoszKowalski
from typing import List
def checkio(game_result: List[str]) -> str:
a = game_result[0]
b = game_result[1]
c = game_result[2]
for i in ["X","O"]:
for x in [a,b,c]:
if x[0]==i and x[1]==i and x[2]==i:
return i
for y in [0,1,2]:
if a[y]==i and b[y]==i and c[y]==i:
return i
if a[0]==i and b[1]==i and c[2]==i:
return i
if a[2]==i and b[1]==i and c[0]==i:
return i
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!")
Dec. 1, 2018