Question: Code the below: A)Write the function greedy change(amount, denominations) that solves the coin exchange problem greedily (i.e., always select the largest coin first). The function

Code the below:

A)Write the function greedy change(amount, denominations) that solves the coin exchange problem greedily (i.e., always select the largest coin first). The function should take in a target amount and a list of infinitely available coins (i.e., denominations) as input. The output should be a sing list of elements where each index represents the count of each denomination.

For example:

>>> greedy_exchange(56, [20, 10, 5, 1])

[2, 1, 1, 1]

> greedy_exchange(350, [100, 50, 10, 5, 2, 1])

[3, 1, 0, 0, 0, 0]

>>> greedy_exchange(12, [9, 6, 5, 1])

[1, 0, 0, 3]

Note: You may assume that the coin denominations will always be given in descending order.

B) Write the function bounded upper lists(upper bounds) that accepts as argument a list of positive integers of length n and returns a list of all lists of length n consisting of non-negative integers with the following property:

-for list lst, holds for all indices i, lst[i] <= upper bound[i].

For example,

>>> bounded_lists([1, 1, 2])

[[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1, 0], [0, 1, 1], [0, 1, 2], [1, 0, 0], [1, 0, 1], [1, 0, 2], [1, 1, 0], [1, 1, 1], [1, 1, 2]]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!