alexioak

counting_change_comb.py

Jul 1st, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. def count_change(money, available_coins, used_coins):
  2.     if sum(used_coins) == money:
  3.         yield used_coins
  4.     elif sum(used_coins) > money:
  5.         pass
  6.     elif available_coins == []:
  7.         pass
  8.     else:
  9.         for c in change(money, available_coins[:], used_coins+[available_coins[0]]): #multiple reccurencies
  10.             yield c
  11.         for c in change(money, available_coins[1:], used_coins): #stop picking coins
  12.             yield c
Advertisement
Add Comment
Please, Sign In to add comment