Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Xs and Os Referee by IanSolWhite
def checkio(r):
rows = r.copy()
rows.extend([''.join(i) for i in zip(*r)])
rows.append(r[0][0] + r[1][1] + r[2][2])
rows.append(r[0][2] + r[1][1] + r[2][0])
if 'XXX' in rows:
return 'X'
elif 'OOO' in rows:
return 'O'
else:
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"
March 20, 2015