Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
range & append only solution in Clear category for Xs and Os Referee by kskkskksk
def checkio(game_result):
#horizontal matches
string_list = game_result
#vertical matches
for i in range(0,3):
string = ""
for e in range(0,3):
string += game_result[e][i]
string_list.append(string)
#diagonal matches
string1 = ""
string2 = ""
for i in range(0,3):
string1 += game_result[i][i]
string2 += game_result[i][2-i]
string_list.append(string1)
string_list.append(string2)
if "OOO" in string_list:
return "O"
elif "XXX" in string_list:
return "X"
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"
April 12, 2015