I have an array @ary = [1, 3, 4, 2, 7, 8, 9]
and I want to know how many possibilities of combination can add equal to 9.
I should have four possibilities can add equal to 9 [1,8]
、[2, 3, 4]
、[9]
、[2, 7]
,but in my code, I just can know two of possibilities and just can show one possibility in this problem.
def sums (num, target)
random1 = num.sample
random2 = num.sample
if random1+random2 == target
ary1 = [random1, random2]
end
end