We need to solve the following problem:

There is an array containing arbitrary numbers:
[3], [5], [2], [6] ....
It is necessary to find the sum of all possible additions of its elements and write them into another array. Those. is obtained if there are 4 elements in the array, the other array should consist of 16.

How to implement the algorithm?

    1 answer 1

    That is, you need to get all possible subsets of this set.

    The simplest option is to take a number of N bits for a set of N elements, and go through all possible values ​​of the number (for 4 elements - from 0000 to 1111, that is, from 0 to 15). Next, for each number, we summarize the elements corresponding to the units of the type, for 0011 - the third and fourth (it is clear that it is more convenient and logical to count from the lower bits, so the zero and the first :))

    I think it will not be a problem to translate into a specific language.

    If the task is specifically in sums - then I would look at the Gray codes , then each subsequent value is obtained by adding or subtracting only one element.