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 VVS
winpatterns=[ 0b111000000, 0b000111000, 0b000000111,
0b100100100, 0b010010010, 0b001001001,
0b100010001, 0b001010100
]
def getPattern(result, sym):
return int(''.join(map(lambda s: "1" if s==sym else "0", ''.join(result)) ), 2 )
def checkio(game_result):
Xp = getPattern(game_result, "X")
Op = getPattern(game_result, "O")
for p in winpatterns :
if p&Xp == p :
return "X"
if p&Op == p:
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"
Aug. 28, 2015
Comments: