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 mcfyang
def checkio(game_result):
possible_wins = game_result[:]
possible_wins.append(''.join(row[0] for row in game_result))
possible_wins.append(''.join(row[1] for row in game_result))
possible_wins.append(''.join(row[2] for row in game_result))
possible_wins.append(''.join(game_result[i][i] for i in range(0, 3)))
possible_wins.append(''.join(game_result[2-i][i] for i in range(0, 3)))
print(possible_wins)
if 'XXX' in possible_wins:
winner = 'X'
elif 'OOO' in possible_wins:
winner = 'O'
else:
winner = 'D'
return winner
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"
April 4, 2016
Comments: