Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Dynamic Programming solution in Clear category for The Stones by Sim0000
def stones(pile, moves):
table = set()
for i in range(1, pile + 1):
if i not in table: table |= {i + m for m in moves}
return 1 if pile in table 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
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 25, 2018
Comments: