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 rn16
from typing import List
def checkio(res: List[str]) -> str:
a, b, c = list(res[0]), list(res[1]), list(res[2])
for i in [a,b,c]:
if len(set(i)) == 1 and '.' not in set(i):
return i[0]
for i in range(3):
if ( (a[i] == b[i] and b[i] == c[i] or
a[i] == b[1] and b[1] == c[abs(2-i)]) and
a[i] != '.' ):
return a[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!")
July 8, 2020