Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
I love lists solution in Clear category for Xs and Os Referee by k_spamowe
def checkio(game_result):
game = []
for string in game_result:
line = [x for x in string]
game.append(line)
for i in range(3):
line = [x[i] for x in game][:3]
game.append(line)
game.append([game[0][0],game[1][1],game[2][2]])
game.append([game[0][2],game[1][1],game[2][0]])
for line in game:
if line.count('X') == 3:
return "X"
elif line.count("O") == 3:
return "O"
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"
Oct. 12, 2015