Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
4-liner! solution in Clear category for The Stones by Merzix
def stones(pile, moves):
game = {x: False for x in range(1, moves[0] + 1)} # True if 1st player wins if x rocks in pile
for stone in range(moves[0] + 1, pile + 1):
game[stone] = any(not game[stone - m] for m in moves if stone > m)
return (2,1)[game[pile]]
if __name__ == '__main__':
assert stones(17, [1, 3, 4]) == 2
assert stones(17, [1, 3, 4, 6, 9]) == 1
assert stones(99, [1]) == 2
assert stones(98, [1]) == 1
Sept. 21, 2018
Comments: