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 artemrudenko
# migrated from python 2.7
def checkio(game_result):
matr = game_result[:]
to_check = list(map(set, matr))
to_check.append(set([matr[i][i] for i in range(3)]))
to_check.append(set([matr[2-i][i] for i in range(2,-1,-1)]))
to_check.extend(list(map(set, list(zip(*game_result)))))
for row in to_check:
if row == set(['X']):
return 'X'
elif row == set(['O']):
return 'O'
return 'D'
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio([
"X.O",
"XX.",
"XOO"]) == "X", "Xs wins"
assert checkio([
"OO.",
"XOX",
"XOX"]) == "O", "Os wins"
assert checkio([
"OOX",
"XXO",
"OXX"]) == "D", "Draw"
Sept. 25, 2013
Comments: