- #1
atrus_ovis
- 101
- 0
Homework Statement
Say we have a given sum, S.
I have to, as part of a more general problem in a program, find all possible distinct terms x1,x2,x3,x4 which when added, give that sum, and the ways they can be rearranged.
Meaning i have to find all 4-tuples that adding one's members gives S.
Term t>=1
For example, for S=10 , terms are 1,2,3,4.
1+2+3+4=10, so all possible tuples are the permutations of 1,2,3,4 which gives us 24 4-tuples
Don't know if it's relevant, but the terms are bounded by a user given number N.
I don't know if such a formula exists or if I'm supposed to find them by exhaustive search, so i turn to you in case the 1st way is doable.
Homework Equations
the permutations formula?
P(n,r) = n! / (n-r)!
The Attempt at a Solution
Haven't accomplished much.
Since S is arbitrary (user-given), i'll have to find a way to generate all valid terms from s.
Since we have 4 slots for the terms, and each term is distinct and greater than 1,
A 'minimum' case would be:
the 3 smallest terms would be 1,2,3 and the remaining S-6
Often in such problems i try a few examples and try to find out patterns.
10-> 1,2,3,4. 24 ways
11-> 1,2,3,5 same
..
14->(1,2,3,8) 24 ways , 2,3,4,5 24 ways
but with no luck..