Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Xs and Os Referee by bart.t
def checkio(game_result):
i = 0
while i < 3:
line = game_result[i]
if line == 'XXX': return 'X'
if line == 'OOO': return 'O'
i +=1
j = 0
while j < 3:
col = game_result[0][j] + game_result[1][j] + game_result[2][j]
if col == 'XXX': return 'X'
if col == 'OOO': return 'O'
j += 1
d1 = game_result[0][0] + game_result[1][1] + game_result[2][2]
d2 = game_result[2][0] + game_result[1][1] + game_result[0][2]
if d1 == 'XXX': return 'X'
if d1 == 'OOO': return 'O'
if d2 == 'XXX': return 'X'
if d2 == 'OOO': 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"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Jan. 24, 2018