In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of December 14th
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #09 exercise sheet]
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
(in this class you are expected to write a solution that uses recursion - mooshak will not force it, but that should be your goal)
Amy Wong-Kroker is planning a shopping spree during her intergalactic travels. She has a set of n coins, each with a specific value. Amy wants to figure out all the unique quantities of money she can create using any combination of these coins (including using none of them).
To satisfy her curiosity, she needs a program that calculates all the distinct quantities she can make. Since Amy is busy shopping for outfits and accessories, she’s leaving this task to you!
Write a function quantities(coins) that receives a list of integers, representing the values of the n coins Amy has. The function should return a set containing all possible unique sums of these coins.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ n ≤ 15 | number of coins |
Example Function Calls | Example Output |
output = quantities([10, 50, 100]) print(sorted(output)) print() output = quantities([1, 1, 5, 5, 12]) print("output is of type", type(output)) print("output has size:", len(output)) for x in sorted(output): print(x) |
[0, 10, 50, 60, 100, 110, 150, 160] output is of type <class 'set'> output has size: 17 0 1 2 5 6 7 10 11 12 13 14 17 18 19 22 23 24 |