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 szymonkukla1
def checkio(x):
i = 0
while(i < 3):
if(x[0][i] == 'X' and x[1][i] == 'X' and x[2][i] == 'X'):
return 'X'
if (x[0][i] == 'O' and x[1][i] == 'O' and x[2][i] == 'O'):
return 'O'
i += 1
i = 0
while (i < 3):
if (x[i][0] == 'X' and x[i][1] == 'X' and x[i][2] == 'X'):
return 'X'
if (x[i][0] == 'O' and x[i][1] == 'O' and x[i][2] == 'O'):
return 'O'
i += 1
if(x[0][0] == 'X' and x[1][1] == 'X' and x[2][2] == 'X'):
return 'X'
if (x[0][0] == 'O' and x[1][1] == 'O' and x[2][2] == 'O'):
return 'O'
if (x[2][0] == 'X' and x[1][1] == 'X' and x[0][2] == 'X'):
return 'X'
if (x[2][0] == 'O' and x[1][1] == 'O' and x[0][2] == 'O'):
return 'O'
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"
Nov. 28, 2016