Last active
December 15, 2015 19:49
-
-
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"
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
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