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 gyahun_dash
def checkio(game_result):
rows = game_result
cols = list(map(''.join, zip(*rows)))
diags = [''.join([rows[i][i] for i in range(3)]),
''.join([rows[i][2 - i] for i in range(3)])]
all_lines = rows + cols + diags
if any('XXX' == row for row in all_lines): return 'X'
elif any('OOO' == row for row in all_lines): return 'O'
else: 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"
March 1, 2014
Comments: