How many of the 6 digit strings 000000 through 999999 have digits which sum to 27? with Build up counting.

163 Views Asked by At

I know we can solve this with $${27 + 5 \choose 5} = {32 \choose 5}$$

but how would I do this $\textbf{strictly with the build up counting method?}$

I was thinking to have the base case $Q(3) = 1$ since this would be '$999$' and less than 3 digits is not possible.

And then we would develop a recursion for strings of length greater than $3$. But I cannot seem to figure this out.

1

There are 1 best solutions below

0
On

Here's a solution that uses generating functions:

$$\text{Let }p(x)=\sum_{i=0}^9x^i=1+x+x^2+\ldots+x^8+x^9.$$

The answer you are looking for will be the coefficient of $x^{27}$ in $\left(p(x)\right)^6$.

I used a TI-92 calculator to find the coefficients of $\left(p(x)\right)^6$. It took nearly a minute, but it eventually got an answer of $55,252$.

Since you asked for a recursive formula, I'll say a little bit about how you could use the above idea to find such a formula.

Define $a(n,k)$ to be the number of $k$-digit strings whose digits add up to $n$. Define $p(x)=1+x+x^2+\ldots+x^8+x^9$, as above, and note that $a(n,k)$ is also the coefficient of $x^n$ in $\left(p(x)\right)^k$.

Now for $k\ge2$, $$\left(p(x)\right)^k=p(x)\cdot\left(p(x)\right)^{k-1}.$$

Using the fact that $a(n,k)$ is the coefficient of $x^n$ in this product, we get the following recurrence relation:

$$a(n,k)=\sum_{i=0}^9 a(n-i,k-1).$$

So to find the number of $6$-digit sequences that whose digits add up to $27$, we could start by noting the following:

$$a(27,6)=\sum_{i=0}^9 a(27-i,5).$$

Then each of $a(27,5)$, $a(26,5)$, ..., $a(18,5)$ could be expressed in terms of $a(27,4)$, $a(26,4)$, ..., $a(9,4)$. Etc.