Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
With lru_cache/setrecursionlimit and without solution in Clear category for The Stones by Phil15
## "Short code" version (it was without sys import)
#from sys import setrecursionlimit # We can't import sys on Checkio's website.
#setrecursionlimit(4000) # we need it if pile is a big number
#from functools import lru_cache
#win1=lru_cache()(lambda n,L:n<1 or(n>min(L)and any(not win1(n-k,L)for k in L)))
## or #win1 = lru_cache()(lambda n, L: n<=0 if n<=min(L) else any(not win1(n-k, L) for k in L))
#stones = lambda pile, moves: (2,1)[win1(pile, tuple(moves))] # tuple is needed for lru_cache
def stones(pile, moves):
one_win_for = set()
for n in range(min(moves) + 1, pile + 1):
if any(n - k not in one_win_for for k in moves if n - k > 0):
one_win_for.add(n)
return (2,1)[pile in one_win_for]
Sept. 20, 2018
Comments: