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 mortonfox
def checkio(game_result):
for i in range(3):
row = game_result[i]
col = ''.join(g[i] for g in game_result)
if row == 'XXX' or col == 'XXX':
return 'X'
if row == 'OOO' or col == 'OOO':
return 'O'
diag1 = ''.join(game_result[i][i] for i in range(3))
diag2 = ''.join(game_result[i][2 - i] for i in range(3))
if diag1 == 'XXX' or diag2 == 'XXX':
return 'X'
if diag1 == 'OOO' or diag2 == 'OOO':
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"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Oct. 4, 2017