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 shuai
# migrated from python 2.7
def checkio(game_result):
# concat the three strings
s = ''.join(game_result)
# all the combinations
comb = ['012', '345', '678', '036', '147', '258', '048', '246']
# iterate
for i in comb:
if s[int(i[0])] == s[int(i[1])] == s[int(i[2])] != '.':
return s[int(i[0])]
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"
Sept. 30, 2015