def stones(pile, moves):
results = [True] + [False] * pile
for count in range(1, pile + 1):
possible = [x for x in moves if count - x >= 0]
results[count] = not any(results[count - i] for i in possible)
return 1 if results[-1]==True else 2
if name == 'main':
print("Example:")
print(stones(17, [1, 3, 4]))
#These "asserts" using only for self-checking and not necessary for auto-testing
#assert stones(17, [1, 3, 4]) == 2
assert stones(17, [1, 3, 4, 6, 9]) == 1
#assert stones(99, [1]) == 2
Created at: 2019/03/16 09:59; Updated at: 2019/03/16 10:07
The question is resolved.