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 welv
def checkio(game_result):
rows = game_result[:]
columns = []
diagonals = []
for i in range(3):
column = ""
for j in range(3):
column = column + rows[j][i]
columns.append(column)
diagonals = [rows[0][0] + rows[1][1] + rows[2][2], rows[0][2] + rows[1][1] + rows[2][0]]
if ("XXX" in rows) or ("XXX" in columns) or ("XXX" in diagonals):
return "X"
elif ("OOO" in rows) or ("OOO" in columns) or ("OOO" in diagonals):
return "O"
else:
return "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. 20, 2017