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 francis.schmidt23
# migrated from python 2.7
def checkio(game_result):
rows = [row for row in game_result]
print(rows)
cols = ["".join([row[i] for row in game_result]) for i in range(len(game_result))]
print(cols)
dias = ["".join([row[i] for (i,row) in enumerate(game_result)]), "".join([row[len(game_result)-1-i] for (i,row) in enumerate(game_result)])]
print(dias)
print(rows + cols + dias)
for line in (rows+cols+dias):
if line == "XXX":
return "X"
elif line == "OOO":
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"
July 7, 2015