Pretty simple idea but harder (for me) in code.
I want to know how many combinations there are to calculate a number X given the numbers I can calculate it from.
Here's an example :
>>> calculate(5, (1,2,5))
4
>>> calculate(42, (1,2,5,10,20))
271
The first example gives 4 because :
- 5
- 2 + 2 + 1
- 2 + 1 + 1 + 1
- 1 + 1 + 1 + 1 + 1
I'm pretty sure this can be done the fast using dynamic programmation or recursive with memorization but can't think of a way of starting the whole thing.
Edit
I want to do this : Find all combinations of a list of numbers with a given sum But for some unknown reason, most of code don't works and other can't even do the simple example of 5 I gave or numbers like 42.