Given an integer n, and an array a, I would like to return an array with all the possible values of sums of a with itself n times.
Example: n = 3, a = [1, 2, 3, 4, 5, 6]
Output: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
First element is from 1+1+1, second is 1+1+2 etc.
Is there any elegant way to do that? I've tried loops, but since n isn't known in advance, I don't know how many loops I need to make.
Thanks in advance