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 evoynov
def checkio(gr):
results = []
for str in gr:
results.append(str)
verticals = ["" for i in range(3)]
for i in range(3):
for str in gr:
verticals[i] += str[i]
results += verticals
diagonals = ["" for i in range(2)]
for i in range(3):
diagonals[0] += gr[i][i]
diagonals[1] += gr[i][2-i]
results += diagonals
return "X" if "XXX" in results else ("O" if "OOO" in results else "D")
if __name__ == '__main__':
#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"
Jan. 31, 2015