Skip to content

Instantly share code, notes, and snippets.

@samartioli
Last active December 15, 2015 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samartioli/5314410 to your computer and use it in GitHub Desktop.
Save samartioli/5314410 to your computer and use it in GitHub Desktop.
Answer in python to problem: "in how many ways can you represent n cents using 25 cents, 10 cents, 5 cents and 1 cent coins"
def append_return(n,L):
M=L[:]
M.append(n)
return M
def cents(n,L=[]):
global t
if n == 0:
#print L
t+=1
if n >= 1:
cents(n-1, append_return(1,L))
if n >= 5:
cents(n-5, append_return(5,L))
if n >= 10:
cents(n-10, append_return(10,L))
if n >= 25:
cents(n-25, append_return(25,L))
def cents_perms(n):
global t
t=0
cents(n)
print(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment