<s>[INST] All 3 digit numbers the sum of whose digits is not greater than 16 My working: Let the digits of the numbers be $x,y,z$ where
\begin{align}1\leq x&\leq 9\\0\leq y,z&\leq 9\\x+y+z &\leq 16 \end{align}
I tried to solve it by making different cases here and using counting but it got really complicated and i couldnt get very far.
So how do i solve such questions?
 [/INST] Let $k\in\{1,2,...,16\}$ a fixed number. If you count the number of triplets $(x,y,z)$ such that $x+y+z=k$, say $S_k$, then you are searching for $S_0+S_1+...+S_{16}$,
Now, by generating functions method, we use the polinomyal $p(x)=(x+x^2+...+x^9)(1+x+x^2+...+x^9)^2$ and we want to find the coefficient of $x^k$.
But 
$\begin{eqnarray}
p(x)&=&(x+x^2+...+x^9)(1+x+x^2+...+x^9)^2\\
&=&x\left(\frac{1-x^{9}}{1-x}\right)\left(\frac{1-x^{10}}{1-x}\right)^2\\
&=&x(1-x^9)(1-x^{10})^2(1-x)^{-3}\\
&=&x(1-x^{9})(1-2x^{10}+x^{20})\sum_{r=0}^\infty\binom{2+r}{2}x^r
\end{eqnarray}$
Now, it is easy to see that for $k=1,...,9$, the coefficient of $x^k$ is $\binom{2+k-1}{2}=\binom{k+1}{2}$.
For $k=10$, the coefficient is $\binom{2+9}{2}-\binom{2+0}{2}=\binom{11}{2}-1$
For $k=11,...,16$, the coefficient is $\binom{2+k-1}{2}-2\binom{2+k-11}{2}-\binom{2+k-10}{2}=\binom{k+1}{2}-2\binom{k-9}{2}-\binom{k-8}{2}$.
So, the answer is 
$\begin{eqnarray}
S_0+...+S_{16}&=&\sum_{k=1}^{16}\binom{k+1}{2}-1-2\sum_{k=11}^{16}\binom{k-9}{2}-\sum_{k=11}^{16}\binom{k-8}{2}\\
&=&816-1-2*56-83\\
&=&620
\end{eqnarray}$
</s>