Question: Python homework Finding a configuration Recall the suitcase-packing problem from the lecture. We are going to turn the problem around and ask instead: given a

Python homework

Finding a configuration

Recall the suitcase-packing problem from the lecture. We are going to turn the problem around and ask instead: given a coin purse of known weight and a set of possible coins, which possible sets of coins satisfy this weight?

We consider a set of coins with the following possible weights and names. (We don't need the names, but it's easier to talk about in troubleshooting.) If they are minted gold tokens, their weight is synonymous with their value.

Index Coin Weight
0 leah 1/8
1 shiblum 1/4
2 shiblon 1/2
3 senine 1
4 antion 1
5 seon 2
6 shum 4
7 limnah 7

Compose a function find_coins( weight ) which accepts a weight and finds all sets of coins that could yield that weight, returning these as a list of lists.

Note that coins could be repeated; that is, for a weight of 1 we could have 8 leahs, 4 shiblums, or 4 leahs and 2 shiblums. To limit this, we will say that we only allow a maximum of twelve coins in a candidate solution. itertools.combinations will not allow repeated items; you instead need to use itertools.combinations_with_replacement. A brute-force search is acceptable.

Your submission should include a function find_coins( weight ).

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 Databases Questions!