<s>[INST] Number of solutions to 3-variable sums with restrictions I came across the following problem

1) How many solutions does the equation $x_1+x_2+x_3=8$ have with integers $x_i\ge0$?

There are $9$ possible values for $x_1$. For each of those, there are $9-x_1$ possible values for $x_2$. And for each of those, there is only $1$ possible value for $x_3$. So To find the total number of solutions, we can sum the number of values for $x_2$ over the actual values of $x_1$.
$$
N=\sum_{x_1=0}^{8}(9-x_1)\cdot1=1+2+3+4+5+6+7+8+9=45
$$
The next two problems were identical, but with added restrictions.

2) How many solutions are there for problem (1) if $x_1\ge2$ and $x_3\ge3$?
3) How many solutions are there for problem (1) if $x_1\le2$ and $x_3\le3$?

Noticing that $N$ must not be too big, I found $N=10$ and $N=12$ by writing out tables of valid solutions. I am not a fan of brute force, however, and I am sure there is a better way of doing this, perhaps involving combinations. I did find this, which is a possible duplicate question, but I didn't quite follow the technique for counting solutions using generator functions. Got any hints to point me in the right direction?
 [/INST] Solving the equation $x_1 + x_2 + x_3 = 8$ involves determining how many ways two plus signs can be placed in a list of eight 1's.  For instance, the list 
$$1 1 1 + + 1 1 1 1 1$$
corresponds to the solution $x_1 = 3, x_2 = 0, x_3 = 5$, while 
$$1 + 1 1 1 1 + 1 1 1$$
corresponds to the solution $x_1 = 1, x_2 = 4, x_3 = 3$.  The number of such lists that can be formed is 
$$\binom{8 + 2}{2} = \binom{10}{2} = \frac{10!}{8!2!} = \frac{10 \cdot 9}{2} = 45$$
To solve the problem $x_1 + x_2 + x_3 = 8$ subject to the restrictions $x_1 \geq 2$ and $x_3 \geq 3$, let 
\begin{align*}
y_1 & = x_1 - 2\\
y_2 & = x_2\\
y_3 & = x_3 - 3
\end{align*}
Then $x_1 = y_1 + 2$ and $x_3 = y_3 + 3$, so we obtain
\begin{align*}
y_1 + 2 + y_2 + y_3 + 3 & = 8\\
y_1 + y_2 + y_3 & = 3
\end{align*}
Applying the same method we used above to the equation $y_1 + y_2 + y_3 = 3$ gives 
$$\binom{3 + 2}{2} = \binom{5}{2} = 10$$
solutions in the non-negative integers. 
To solve the problem $x_1 + x_2 + x_3 = 8$ in the non-negative integers subject to the restrictions $x_1 \leq 2$ and $x_3 \leq 3$, we must subtract the number of solutions in which $x_1 \geq 3$ or $x_3 \geq 4$ from the $45$ solutions of the equation in the non-negative integers.  To do so, we subtract the number of solutions in which $x_1 \geq 3$ and the number of solutions in which $x_3 \geq 4$, then add the number of solutions in which both $x_1 \geq 3$ and $x_3 \geq 4$ since those solutions would otherwise be subtracted from the total number of solutions twice.
The number of solutions of the equation $x_1 + x_2 + x_3 = 8$ in which $x_1 \geq 3$ is the number of solutions of the equation
\begin{align*}
y_1 + 3 + y_2 + y_3 & = 8\\
y_1 + y_2 + y_3 & = 5
\end{align*}
in the non-negative integers, which is 
$$\binom{5 + 2}{2} = \binom{7}{2} = 21$$
The number of solutions of the equation $x_1 + x_2 + x_3 = 8$ in which $x_3 \geq 4$ is the number of solutions of the equation 
\begin{align*}
y_1 + y_2 + y_3 + 4 & = 8\\
y_1 + y_2 + y_3 & = 4
\end{align*}
in the non-negative integers, which is 
$$\binom{4 + 2}{2} = \binom{6}{2} = 15$$
The number of solutions of the equation $x_1 + x_2 + x_3 = 8$ in which $x_1 \geq 3$ and $x_3 \geq 4$ is the number of solutions of the equation
\begin{align*}
y_1 + 3 + y_2 + y_3 + 4 & = 8\\
y_1 + y_2 + y_3 & = 1
\end{align*}
in the non-negative integers, which is
$$\binom{1 + 2}{2} = \binom{3}{2} = 3$$
Hence, the number of solutions of the equation $x_1 + x_2 + x_3 = 8$ in the non-negative integers in which $x_1 \leq 2$ and $x_3 \leq 3$ is $45 - 21 - 15 + 3 = 12$.  
</s>