Generate all combinations possible to get to a certian number

79 Views Asked by At

Say I have an array of 3 numbers:

[1,2,3] and I need to generate ALL possible ways to get to a number 21. 1 repeated 21 times would be one way. 1 repeated 19 times, than adding 2 would be another etc.

How do I write an algo for this? I've tried but most solutions focus on generating combinations from unique numbers.