Created
July 28, 2012 00:07
-
-
Save KartikTalwar/3191145 to your computer and use it in GitHub Desktop.
Simple Greedy Coin Algorithm
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 bestChange(denominations, amount): | |
if amount == 0: | |
return [] | |
for i in denominations: | |
if i <= amount: | |
return [i] + bestChange(denominations, amount-i) | |
denominations = [100, 50, 20, 10, 5, 2, 1] | |
amount = 109 | |
print bestChange(denominations, amount) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment