12 Sep 2020 - Hadron DaVinci
You have unlimited $20 dollar bills, unlimited $10 dollar bills, unlimited $5 dollar bills, and unlimited $1 dollar bills.
How many ways can you make change for a $100 dollar bill?
Truths:
In a previous post, I created a function which
could be used to solve many coin change problems.
Internally, it uses a double loop along with recursion to create a list of coins that sum to the target value.
You can find more about that post here.
Example
import sys
coin_values = [20, 10, 5 1] quantity = [sys.maxsize, sys.maxsize, sys.maxsize, sys.maxsize] target_value = 100 SOLUTIONS = []
foo(coin_values, quantity, target_solutions) max_count = 0 min_count = 0
for s in SOLUTIONS: max_count = max(len(s), max_count) min_count = min(len(s), min_count)
print("Max Number of Bills Needed Is:", max_count) print("Min Number of Bills Needed Is:", min_count)