Skip to content

Instantly share code, notes, and snippets.

@falsetru
Created June 18, 2012 02:32
Show Gist options
  • Save falsetru/2946497 to your computer and use it in GitHub Desktop.
Save falsetru/2946497 to your computer and use it in GitHub Desktop.
from functools import lru_cache
coins= 10,20,50,100,200,500,1000,2000,5000,10000
@lru_cache(None)
def count(amount, idx=len(coins)-1):
if amount < 0 or idx < 0: return 0
if amount == 0: return 1
return count(amount - coins[idx], idx) + count(amount, idx-1)
print(count(1000000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment