14
3
Challenge
Suppose you have a list of numbers, and a target value. Find the set of all combinations of your numbers which add up to the target value, returning them as list indices.
Input and Output
The input will take a list of numbers (not necessarily unique) and a target summation number. The output will be a set of non-empty lists, each list containing integer values corresponding to the position of the values in the original input list.
Examples
Input: values = [1, 2, 1, 5], target = 8
Output: [ [0,1,3], [1,2,3] ]
Input: values = [4.8, 9.5, 2.7, 11.12, 10], target = 14.8
Output: [ [0,4] ]
Input: values = [7, 8, 9, -10, 20, 27], target = 17
Output: [ [1,2], [0,3,4], [3,5] ]
Input: values = [1, 2, 3], target = 7
Output: [ ]
Scoring
This is code-golf, so the shortest code wins!
6Related, possibly a dupe. – Giuseppe – 2018-01-15T01:40:29.293
I think this is a dupe but I would rather close the older one because it is outdated. – Post Rock Garf Hunter – 2018-01-15T01:56:15.637
4Do floating point numbers really add something to the challenge? Not sure what the consensus is, but they will probably lead to precision errors in many languages. – Arnauld – 2018-01-15T01:59:57.747
I was intending to allow for floating points, yes – soapergem – 2018-01-15T02:14:37.727
14Bleh, indices? I think this would be a nicer challenge returning a list of values, though I guess that raises a question with how repeated values are dealt with in subsets. – xnor – 2018-01-15T02:22:46.590
@HeebyJeebyMan Have you "close the older one"? – user202729 – 2018-01-15T13:24:03.647
@user202729 I have voted to now. Prior I was unable to because this one had no answers. – Post Rock Garf Hunter – 2018-01-15T16:19:33.927