Python function: Find Change from purchase amount

前端 未结 6 793
旧时难觅i
旧时难觅i 2021-01-29 13:56

I\'m looking for the most efficient way to figure out a change amount (Quarters, dimes, nickels, and pennies) from a purchase amount. The purchase amount must be less than $1, a

6条回答
  •  猫巷女王i
    2021-01-29 14:29

    This problem could be solved pretty easy with integer partitions from number theory. I wrote a recursive function that takes a number and a list of partitions and returns the number of possible combinations that would make up the given number.

    http://sandboxrichard.blogspot.com/2009/03/integer-partitions-and-wiki-smarts.html

    It's not exactly what you want, but it could be easily modified to get your result.

提交回复
热议问题