Created
January 23, 2017 19:00
-
-
Save styx97/542dc6eabcdbab2901e91af118e80258 to your computer and use it in GitHub Desktop.
Solving problems in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [1,4,5,10] | |
cache = {} | |
for i in a: | |
cache[i] = 1 | |
counter = 0 | |
def coin(x): | |
if not x in cache: | |
tmp = [] | |
for i in a: | |
if (x-i) > 0: | |
if (x-i) in cache: | |
tmp.append(1+cache[x-i]) | |
else: | |
tmp.append(1+coin(x-i)) | |
cache[x] = min(tmp) | |
return cache[x] | |
else: | |
return cache[x] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment