# Find all non-negative integer solutions of $x+y+z=20$

I'm looking for all non-negative integer solutions to $x+y+z=20$ and I reason this way: I essentially take $\overbrace{1 + 1 + ... + 1}^{\text{20}}$ and segment this into three groupings. In essence that's the same as picking two divisions somewhere in the list of 1s. For 20 numbers there are 20 places at which to insert a dividing line, including before the first 1 and after the last.

My main thought at this point is that I want to find the number of ways of picking two things from a pool of 20, using $_{20}C_2$, but that selects without replacement. However, in this case it seems that I should be able to select any dividing location more than once (representing one of the variables being equal to 0).

Is the answer then $_{20}C_2$ for non-zero solutions, then for solutions including zero we could assume $x$ is zero and then there are 20 solutions to $y+z=20$, and 20 for $x+z=20$ and 20 for $x+y=20$ so sum these all together?

[Edit: ... and subtract off the number of solutions that have both $x=0=y$ and so on, so that would be subtracting off 3 solutions.]

• en.wikipedia.org/wiki/Stars_and_bars_(combinatorics) might be of some assistance here? – Steven Stadnicki Nov 2 '15 at 4:45
• Without loss of generality, you need only consider one of the cases where one of the variables is zero, unless you are saying that (0,5,15) is a different solution to (5,0,15)? – MrMazgari Nov 2 '15 at 4:46
• @JVV Wouldn't they be separate solutions? Especially when representing them as points it seems to strongly suggest that they are distinct. – Addem Nov 2 '15 at 4:48
• Depends on the context. If you are thinking of them as points in the plane, then yes they are different, but generally, when solving diophantine equations, one usually makes assumptions on the variables in order to obtain primitive solutions. – MrMazgari Nov 2 '15 at 4:51

I prefer not to insert dividing lines at the ends.

Here is a solution appropriate for October 31. Three kids come to your door, and you want to distribute $20$ identical candies between them, with perhaps some kid(s) getting nothing.

Line up $23$ candies. There are $\binom{22}{2}$ ways to insert $2$ dividing lines between the candies. Give each kid the number of candies determined by the dividing lines. Then (the difficult part) take away a candy from each kid. Each way of dividing $20$ candies between the kids, with possibly some kid(s) getting none, arises in a unique way from the process of distributing $23$ candies between them, at least one to each, and then taking away a candy from each.

So there are $\binom{22}{2}$ ways to do the job.

• While I'm digesting the logic of this, I'm thoroughly amused by your little story to go with it. :) – Addem Nov 2 '15 at 5:20
• From reading the question I thought the OK wanted to find all of the solutions, but apparently he only wanted the number of solutions. I wonder how you knew that. – bof Nov 2 '15 at 8:14
• @bof: OP showed work in some detail, and from that work what was being sought seemed clear. – André Nicolas Nov 2 '15 at 8:20

The general solution for such sums is $\binom{n+k-1}{k-1}$. Here $n=20$ and $k=3$ so the number of solutions is $\binom{20+3-1}{3-1}=\binom{22}{2}=231$. I hope this helps you.

In lines of partition of numbers:

Number of partitions of $20$ of size $3,2,1$ are $33,10,1$ respectively.

Now, if ordering doesn't matter ($x\le y\le z$), number of non-negative integer solutions $= 33+10+1=44$

If ordering is important, number of non-negative integer solutions $=3!\times 33+{3\choose2}\times 10 + 3=231$

Each $3$-Partition of 20 can be arranged in $3!$ different ways, each $2$-Partitions in ${3\choose2} =3$ different ways, and $1$-Partitions in 3 different ways ($x=20,y=20$ or $z=20$)

(I used wolfram alpha to find number of partitions of size n, shared it here since it is a different approach to the problem.)