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 Bacek
def checkio(g):
for i in range(3):
if len(set(g[i][0]) & set(g[i][1]) & set(g[i][2])) and g[i][0] != '.': return g[i][0]
if len(set(g[0][i]) & set(g[1][i]) & set(g[2][i])) and g[0][i] != '.': return g[0][i]
if len(set(g[0][0]) & set(g[1][1]) & set(g[2][2])) and g[0][0] != '.': return g[0][0]
if len(set(g[2][0]) & set(g[1][1]) & set(g[0][2])) and g[2][0] != '.': return g[0][2]
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"
Feb. 13, 2015