Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Stones by Pavel_Surzhenko
def stones(pile, moves):
field = []
for i in range(pile):
field.append(isWinning(field, moves))
return 2 if field[-1] else 1
def isWinning(previous, moves):
l = len(previous)
for move in moves:
if l - move >= 0 and previous[l - move]:
return False
return True
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. 19, 2018