How to compute the sum of subsets?

I am new to elixir and i’m stuck at the problem for writing subsets of a list whose sum would be the target number

array = [3, 5, 2, 7, 4, 2, 3]
iex> sum(array, 10)

desired output :

[[3, 7], [3, 2, 5], [3, 2, 5], [3, 4, 3], [7, 3], [3, 2, 2, 3], [2, 5, 3], [2, 5, 3]]

plz help me

Imagine the numbers in the list (in Elixir we have lists not arrays) lying in front of you as playing cards, how would you find the cards that together have the sum of 10?

1 Like

This particular problem has been coming up a lot lately; you might take some inspiration from this thread which seems to be solving the next part of the problem (removing duplicates).

If this is for the eYRC then IMO posting the problem statement in a forum and saying “plz help me” is not doing your own work.

5 Likes