Skip to content

Instantly share code, notes, and snippets.

@yanolab
Created May 2, 2014 22:04
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 yanolab/9e6edc56c3af96bbfe81 to your computer and use it in GitHub Desktop.
Save yanolab/9e6edc56c3af96bbfe81 to your computer and use it in GitHub Desktop.
coins.py
# -*- coding: utf-8 -*-
def product(v, coins=[500, 100, 50, 10, 5, 1], used=[]):
if len(coins) == 1:
yield 1
else:
for i, coin in enumerate(coins):
diff = v - coin
if diff == 0:
yield 1
elif diff >= 0:
for x in product(diff, coins[i:], used + [coin]):
yield x
print sum(product(1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment