Created
January 12, 2011 22:01
-
-
Save georgemarshall/776994 to your computer and use it in GitHub Desktop.
Solve the coin change problem
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
#!/usr/bin/env python | |
# encoding: utf-8 | |
def change(value, denominations=[0.25, 0.10, 0.05, 0.01]): | |
change = {} | |
for denomination in denominations: | |
change[denomination] = 0 | |
while value - denomination >= 0: | |
change[denomination] += 1 | |
value -= denomination | |
return change | |
def main(): | |
print 'Num coins:', change(0.99) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment