Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def splitIntoBills(money, denominations=None):
- denominations = denominations or {100: -1, 50: -1, 20: -1, 10: -1, 5: -1, 1: -1}
- billsPerDenom = {}
- for i in sorted(denominations, reverse=True):
- denom, billsLeft = i, denominations[i]
- bills = math.floor(money / denom)
- if billsLeft >= 0: bills = min(bills, billsLeft)
- billsPerDenom[denom] = bills
- money -= (bills * denom)
- billsPerDenom["left"] = money
- return billsPerDenom
- # >>> splitIntoBills(842)
- # {100: 8, 50: 0, 20: 2, 10: 0, 5: 0, 1: 2, 'left': 0}
- #
- # >>> splitIntoBills(842, {100: 3, 50: -1, 20: -1, 10: -1, 5: -1, 1: -1})
- # {100: 3, 50: 10, 20: 2, 10: 0, 5: 0, 1: 2, 'left': 0}
- #
- # >>> splitIntoBills(842, {20: -1})
- # {20: 42, 'left': 2}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement