Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Xs and Os Referee by baozhao123
# migrated from python 2.7
def checkio(game_result):
map={'X' : 1, 'O' : -1, '.' : 0}
count = [0]*8
for i in range(3):
for j in range(3):
count[i] += map[game_result[i][j]]
count[3+j] += map[game_result[i][j]]
count[6] = sum([map[game_result[i][i]] for i in range(3)])
count[7] = sum([map[game_result[i][2-i]] for i in range(3)])
if count.count(3) > 0:
return 'X'
if count.count(-3) > 0:
return 'O'
return "D"
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio([
"..O",
"XX.",
"OOX"]) == "D", "Xs wins"
assert checkio([
"OOO",
"X.X",
"XOX"]) == "O", "Os wins"
assert checkio([
"OOX",
"XXO",
"OXX"]) == "D", "Draw"
assert checkio([
"O.X",
"XX.",
"XOO"]) == "X", "Xs wins again"
April 3, 2015