Skip to content

Instantly share code, notes, and snippets.

@styx97
Created January 23, 2017 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save styx97/542dc6eabcdbab2901e91af118e80258 to your computer and use it in GitHub Desktop.
Save styx97/542dc6eabcdbab2901e91af118e80258 to your computer and use it in GitHub Desktop.
Solving problems in python
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