Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Xs and Os Referee by bitt-boy
from itertools import compress
def checkio(game_result):
goals = (map(int, (','.join(f'{n:09b}').split(','))) for n in (7, 56, 73, 84, 146, 273, 292, 448))
res = ''.join(game_result)
for n in (list(compress(res, n)) for n in goals):
if n == ['X', 'X', 'X']:
return 'X'
elif n == ['O', 'O', 'O']:
return 'O'
return 'D'
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!")
April 22, 2019