Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
intersection solution in Clear category for Xs and Os Referee by kalauroma7997
def checkio(rows):
d = {'XXX': 'X', 'OOO': 'O', 'DDD': 'D'}
cols = list(map(''.join, zip(*rows)))
diags = list(map(''.join, zip(*((l[i], l[2-i]) for i, l in enumerate(rows)))))
results = set(rows).union(cols+diags)
return d[(list(results.intersection(d)) + ['DDD'])[0]]
if __name__ == '__main__':
print("Example:")
print(checkio(["X.O",
"XX.",
"XOO"]))
#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"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Nov. 7, 2020
Comments: