Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
check all cases solution in Clear category for Xs and Os Referee by nickgryg
from typing import List
def checkio(xo: List[str]) -> str:
for i in range(3):
if xo[0][i] == xo[1][i] == xo[2][i] != ".":
return xo[0][i]
break
for j in range(3):
if xo[j][0] == xo[j][1] == xo[j][2] != ".":
return xo[j][0]
break
if xo[0][0] == xo[1][1] == xo[2][2] != "." or xo[0][2] == xo[1][1] == xo[2][0] != ".":
return xo[1][1]
else:
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!")
Aug. 16, 2018
Comments: