I was presented with the below problem and I am not sure how to go about it due to the grid laylout and inexperience with math functions.
Write a function to create permutations from the following set of numbers such that the sum of three or less numbers equals to 1 or 2 or 3 or 4 or 5. Then group the permutations based on their sums. For example:
[z,b];[y,a];[x,a];... belong to the permutation set 1
[z,b][y,a];[z,e];[y,a][x,a].... belong to the permutation set 2
a, b, c, d, e
z 3, 1, 5, 4, 2
y 1, 3, 2, 5, 4
x 1, 4, 3, 5, 2
w 3, 2, 5, 1, 4
v 4, 1, 5, 2, 3
u 3, 2, 4, 5, 1
t 1, 5, 4, 2, 3
s 5, 2, 1, 4, 3
r 5, 3, 2, 4, 1
q 5, 3, 4, 1, 2
- The sum of 3 or fewer numbers is either 1,2,3,4 or 5
For example: [z,a]=>3 [z,b]=>1 + [z,e]=>2 = 3
So, [ [[z,a]], [[z,b],[z,e]] ] is a sample solution set of a permutation of elements whose sum is 3. Also, each of the sets in the solution set contains 3 or fewer elements.
- Group the permutations based on their sum From the above example, [ [[z,a]], [[z,b],[z,e]] ] is a permutation set of elements whose sum is 3.
Similarly, there will be more elements in the permutation set of elements whose sum is 3. Also, there will be permutation sets of elements whose sum is either 1,2,4 or 5.
inexperience with math functions.It's not really a maths problem, unless you don't know whata+b+cmeans.. :)