Assume
n = 3 //A,B,C
x = 6
How to find all permutaions of three numbers which makes to the total of 6. For example how to calculate how many permutations we can find.
A B C
----------
0 0 6
0 6 0
6 0 0
0 1 5
1 0 5
0 5 1
1 5 0
5 0 1
5 1 0
0 2 4
1 1 4
2 0 4
0 4 2
2 4 0
1 4 1
4 1 1
4 0 2
4 2 0
3 0 3
3 3 0
0 3 3
3 2 1
3 1 2
1 3 2
2 3 1
1 2 3
2 1 3
2 2 2
What is the formula to count the purmutations for given x and n, to get results like above? Is there any programatical way to do this
First, find how many different groups of numbers sum to $6$, and write them as an unordered set. $\left \{ 1,2,3 \right \},\left \{6,0,0 \right \},\left \{5,1,0 \right \},\left \{2,4,0 \right \}$
Now find how many ways you can "shuffle" or arrange the numbers in each of these sets. Each set has $3$ elements, that means there are $3!$ ways to arrange each set. There are $4$ sets, so; $3!\times4=28$