Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Xs and Os Referee by olekszymczak
from typing import List
def checkio(a: List[str]) -> str:
for i in a:
sign=i[0]
if i==3*sign and sign!=".":
return sign
for i in range(len(a)):
sign=a[0][i]
if a[1][i]==sign and a[2][i]==sign and sign!=".":
return sign
if a[1][1]==a[2][2] and a[0][0]==a[1][1] and a[0][0]!=".":
return a[0][0]
if a[0][2]==a[1][1] and a[1][1]==a[2][0] and a[1][1]!=".":
return a[1][1]
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. 28, 2018