I’m having a problem w/ my program. I have extracted a set of data and I would like to test if there is a combination for a particular number. For example, I have an array of int, 1 2 3 4 5, I would like to know if there is a combination for 7 maybe, and it must answer yes there is 3 + 4.
I figured out that I need to use the combination formula. So I thought that the outer loop may go like 5C1..5C2..5C3..etc, starting to “take 1” then “take 2” at a time to find out all the possible combinations. The problem is I’m stuck at how to implement this in actual codes.
I’m not really very good with Math, A defined loop structure would really help.
Thanks a lot in advance!
Here is a method that gets all possible sums from a List of Integers:
Usage:
Output:
While this solution won’t give you the operands that lead to the sum, it will include anything from
1to1 + 2 + 3 + 4 + 5 + 6