11
Write a function that gets as an input a sorted array of positive numbers A
, and an additional number n
. The Task is to print out all distinct subsets of A
, that sum to n
.
Example:
Input:
A = [1,2,2,4,4]
n = 9
Output:
[1,2,2,4]
[1,4,4]
Bonus: -50% if your code doesn't store duplicate subset (the same subset but in different order) intern. The function will not store more than one duplicate subset in memory at a time.
Shortest code in bytes wins.
Are duplicates allowed in the output? – Conor O'Brien – 2016-03-18T00:19:07.653
1What do you mean by "store"? Will input numbers always be positive integers? – Luis Mendo – 2016-03-18T00:24:33.290
store for example would be: to iterate over all subsets and store in a big array all feasible subsets and then remove all redundant ones. – zboyz – 2016-03-18T00:37:46.443
If duplicates are stored, can they be produced in the output? Or do they need to be removed before displaying? – Luis Mendo – 2016-03-18T00:38:56.753
No only the distinct subsets should be displayed. – zboyz – 2016-03-18T00:41:03.180
2If a duplicate is generated, checked for uniqueness and then discarded, does that qualify for the bonus? The duplicate needs to be temporarily stored somehow. Perhaps the bonus rule could be more precise saying at most one duplicate can be present at any time? – Luis Mendo – 2016-03-18T00:45:51.443
1yes that is what i meant. i will add it. – zboyz – 2016-03-18T00:48:54.657
9
Bonuses are generally discouraged in [tag:code-golf]. I suggest that you decide on a single version of the challenge (bonus either required or not).
– lirtosiast – 2016-03-18T01:31:20.033