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 tarasenkoa
def checkio(game_result):
r = game_result
for i in range(len(r)):
if r[i][0] == r[i][1] == r[i][2] != ".":
return r[i][0]
if r[0][i] == r[1][i] == r[2][i] != ".":
return r[0][i]
if r[0][0] == r[1][1] == r[2][2] != ".":
return r[0][0]
if r[2][0] == r[1][1] == r[0][2] != ".":
return r[2][0]
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. 20, 2015
Comments: