Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
From the bottom up solution in Clear category for The Stones by HeNeArKr
# Build results table up from the bottom
def stones(pile, moves):
""" Return number of winning player, assuming that each player makes the
best possible move at each turn.
"""
low = min(moves) + 1
winner = {n: False for n in range(1, low)} # True = player 1 wins
for total in range(low, pile+1):
winner[total] = not all(winner[total-choice] for choice in moves
if total > choice)
return 1 if winner[pile] else 2
Sept. 19, 2018