Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Divide and rule ?

Answered: 1 week ago