Skip to content

Instantly share code, notes, and snippets.

@georgemarshall
Created January 12, 2011 22:01
Show Gist options
  • Save georgemarshall/776994 to your computer and use it in GitHub Desktop.
Save georgemarshall/776994 to your computer and use it in GitHub Desktop.
Solve the coin change problem
#!/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