Combinatorics – How to Find Numbers Between 100 and 900 with Digit Sum 15

combinatorics

How many numbers between $100$ and $900$ have sum of their digits
equal to $15$?

I was wondering if we could derive any direct combinatoric formula to solve problem like this,my strategy is kind of trying all permutation for $100$ to $200$ then $200$ to $300$ then …,and finally summing them up to get $62$ (if I there is not mistake)though this may not be very difficult to solve using this approach (as we are dealing with $3$ digits numbers with individual digits not greater than $9$)but is this also the fastest/efficient one?

Best Answer

This problem can be reduced to solving

$$x_1 + x_2 + x_3 = 15, \quad 0 \leq x_i \leq 9, \quad x_1 \neq 0, \quad x_1 \neq 9$$

First, we solve

$$x_1 + x_2 + x_3 = 15, \quad 0 \leq x_i \leq 15$$

This is a standard stars and bars problem, with solution $\binom{15+3-1}{15} = 136$. Now which solutions are wrong? Well, first of all those with one of them above $10$. But if, say, $x_1 \geq 10$, then we can write $x_1' = x_1 - 10$ and $x_2' = x_2, x_3' = x_3$ to reduce the problem to

$$x_1' + x_2' + x_3' = 5, \quad 0 \leq x_i' \leq 5$$

This is again a standard stars and bars problem, with solution $\binom{5+3-1}{5} = 21$. Since exactly one of $x_1,x_2,x_3$ could be above $10$, this gives $3 \cdot 21 = 63$ wrong solutions in total. So there are $136 - 63 = 73$ solutions to

$$x_1 + x_2 + x_3 = 15, \quad 0 \leq x_i \leq 9$$

Finally, we need to subtract $4$ solutions with $x_1 = 0$ (i.e. $(x_2,x_3) \in {(6,9),(7,8),(8,7),(9,6)}$), but also subtract $7$ solutions for $x_1 = 9$ (i.e. $(x_2,x_3) \in {(0,6),\ldots,(6,0)}$). This gives $62$ solutions in total.