-1

I have a task to write a function(n) that finds all the sequences that consists of only 1, 3, 4 (not sure how to explain it in english but i have example below)

For example if n is equal to five then i should print out

5 = 1+1+1+1+1
5 = 1+1+3
5 = 1+3+1
5 = 3+1+1
5 = 1+4
5 = 4+1

I'm not sure how should i go about writing it.

vynnix
  • 11
  • 1

1 Answers1

0

Just finding the right terminology might be an answer:

"You are trying to get all the permutations of the values 1, 3 and 4, that sum up to 5."

Unlike combinations, with permutation the order maters. Wich is why {1,4} and {4,1} are both seperate, valid answers. Same with the {1,1,3} variations. I would say this is a hard recursive problem. I am a bit a a loss for the function signature right now, as the reference nature of arras could become a big issue.

just finding all the combinations and then creating all the permutations of each set could work.

Christopher
  • 9,634
  • 2
  • 17
  • 31