4

Find all $4$ digit numbers such that sum of digits is $11$. \begin{cases} x_1+x_2+x_3+x_4=11\\ 1\leq x_1{\leq 9}\\ 0\leq x_2{\leq 9}\\0\leq x_3{\leq 9}\\ 0\leq x_4{\leq 9}\end{cases}.

Using stars and bars there is 13 choose 3 ways to do. So we get $286$ but answer is $279$. I saw this same question in the forum but didn't fully understand solution. Where we are overcounting when solving in this way? And mainly what we are overcounting?

miracle173
  • 11,049
  • 1
    Your solution does not check for $x_i$ being $\le 9$. Thus you have seven "numbers" which are not actually numbers, with "digits" greater than $9$: $A100, A010, A001, 1A00, 10A0, 100A, B000$ (with $A$ meaning "digit $10$" and $B$ meaning "digit $11$"). –  May 21 '22 at 17:53

3 Answers3

7

As stated by Stinking Bishop in the comments, you are overcounting e.g. the "number" $(x_1, x_2, x_3, x_4) = (11, 0, 0, 0)$. The problem is that your stars and bars method does not account for your stated constraints $0\leq x_i\leq 9$.

Therefore, we need to subtract the extra cases where one of the digit is at least $10$. If there's a $10$, it must be some permutation of $(10, 1, 0, 0)$, so there are $6$ cases (note that $0$ cannot be first digit). If there's a $11$, then it must be $(11, 0, 0, 0)$, so there is $1$ case here. Therefore, there is $286 - 6 - 1 = 279$ cases in total.

Challenge for you: Do the same problem for sum of digits $S = 12$ and $13$. There should be $342$ and $405$ respectively.

Gareth Ma
  • 3,725
  • Won't this method involve tedious counting, even for $S=13 ?$ – true blue anil May 25 '22 at 08:58
  • $S = 13$ the only overcounts are $(10, 3, 0, 0), (10, 2, 1, 0), (10, 1, 1, 1), (11, 2, 0, 0), (11, 1, 1, 0), (12, 1, 0, 0), (13, 0, 0, 0)$ and their restricted permutations. Not the hardest? @trueblueanil – Gareth Ma May 25 '22 at 11:36
  • Not the easiest, either ! Compare with $\binom{15}3- \binom63 - 3\binom53$ – true blue anil May 25 '22 at 11:47
  • @trueblueanil Not claiming it's easier than GF or IE, just saying that it is not tedious, and probably suits OP's intuition level (from what I can tell). – Gareth Ma May 25 '22 at 11:58
  • It is very apt for $S=11$, I had also posted in a somewhat similar vein, but then discarded it as not very suitable as $S$ grows. Your answer is fine, just a point of view. Have a good day ! :-) – true blue anil May 25 '22 at 12:25
4

In this answer it is described how to solve this by generating functions. The solution is the coefficient of the degree $11$ monomial of the polynomial

$$(x+x^2+\cdots+x^9)(1+x+x^2+x^3+\cdots+x^9)^3$$

This coefficient can be calculated by a CAS like Mathematica as shown in the link above. It can even calculated by a numerical calculator that can handle arbitrary length integers as describe in the second half of my answer here. But in this answer I learned in one of the comments how to calculate this by hand.

Note that

$$\frac 1 {1-x}=\sum_{n=0}^\infty x^n$$ and by differentiation using induction you get

$$\frac 1 {(1-x)^k}=\sum_{n=0}^\infty{ n+k-1 \choose k-1} x^n$$

So we have

$$(x+x^2+\cdots+x^9)(1+x+x^2+x^3+\cdots+x^9)^3\\ =x\frac{1-x^9}{1-x}\frac{(1-x^{10})^3}{(1-x)^3}\\ =x(1-x^9)(1-x^{10})^3 \sum_{n=0}^\infty{ n+3 \choose 3} x^n\\ =(x-x^{10}-3x^{11}+3x^{20}+\cdots)\frac 1 6 (1\cdot2\cdot3+2\cdot 3 \cdot4\cdot x+\cdots+11\cdot 12\cdot 13\cdot x^{10} \cdots )\\ =\cdots +\cdot \frac 1 6 (-3\cdot 1\cdot 2 \cdot 3-2\cdot 3\cdot 4+11\cdot 12 \cdot 13)x^{11}+\cdots\\ =\cdots+279x^{11}+\cdots$$

The coefficients of the monomials of degree greater than $36$ cancel out.

We have

$$ \frac{\left( {{x}^{40}}-{{x}^{31}}-3 {{x}^{30}}+3 {{x}^{21}}+3 {{x}^{20}}-3 {{x}^{11}}-{{x}^{10}}+x\right) \, \sum_{n=0}^{\infty }{\left. \left( {{n}^{3}}+6 {{n}^{2}}+11 n+6\right) {{x}^{n}}\right.}}{6} $$

We abbreviate $$f(n):={{n}^{3}}+6 {{n}^{2}}+11 n+6$$ and verify that $$f(n+39)-f(n+30)-3f(n+29)+3f(n+20)+3f(n+19)-3f(n+10)-f(n+9)+f(n)=0$$ and $$f(n+39)-f(n+30)-3 f(n+29)+3 f(n+20)+3 f(n+19)-3 f(n+10)-f(n+9)$$ for $n=-1,-2,-3$ because $f(n)=0$ for this values

miracle173
  • 11,049
  • Is my understanding correct that the $\frac{1}{6}\cdots$ is infinite? If so, does that mean $[x^n]$ will have a value even for $n \geq 37$? Or does it just magically cancel to $0$, since the first expression is finite (that will be very cool). – Gareth Ma May 25 '22 at 12:27
  • @GarethMa Yes, it is infinite. For n>37 the values magically and algebraically cancel out. Of course it should be possible to prove this. But I only did a calculation with a CAS until $n=200$ and this shows that the coefficients for n>36 cancel out. I edited my post – miracle173 May 25 '22 at 14:07
  • That's cool. Using Sage, I also verify that the expression is correct: (x*(1-x^9)*(1-x^10)^3*sum(binomial(n+3,3)*x^n,n,0,oo)).full_simplify() gives a polynomial of degree $36$. Sage is great :D – Gareth Ma May 25 '22 at 14:09
  • @I see now, that this is easy to prove. Changed my post accordingly – miracle173 May 25 '22 at 15:29
3

As is usual, in using stars and bars, we often need to apply inclusion-exclusion if there is an upper limit.
Here there are also differing lower limits, so we will first equalize the lower limits by preplacing a digit in $x_1$, so
$\;x_1+x_2+x_3+x_4 = 10,$
and upper limit becomes $8$ for $x_1$ and $9$ for the rest, so if we put $9$ in the first digit or $10$ in any other, they are the "bad" cases to be excluded.

and we get $\binom{13}3 -\binom 11\binom{13-9}3 - \binom31\binom{13-10}3 = 279$


The other alternative is to use generating functions, and find the coefficient of $x^{11}$ in $(x^1+x^2+x^3+...+x^9)(x^0+x^1+x^2+x^3+...+x^9)^3$

with the first multiplicand standing for the first digit, yielding the same answer of $279$