0

I am making an error in my thinking about this problem, and I'd appreciate a clue as to where I'm going wrong. Let's say we have combinations of nine digits 0-9, of which there are a billion, or $10^9$ possible strings of digits. How can we find the number of strings that have at least one 8 in them?

Correct Answer: If you subtract the number of strings with no 8 in them, of which there are $9^9$ (nine possible digits in nine slots) from the total number of 9 digit strings ($10^9$), then the desired number is $10^9-9^9$.

Erroneous Answer: Consider nine strings: 8xxxxxxxx, x8xxxxxxx, ... , xxxxxxxx8. For each of these nine, we need every combination of the other eight "mystery digits". There are $10^8$ such combinations for the mystery digits for each of the nine strings, so multiplying gives $9*10^8$ combinations.

Clearly, the erroneous answer is far larger than the correct one. So where did I go wrong?

2 Answers2

2

I figured out where I went wrong while typing this out. Consider two of the strings from the erroneous answer: 8xxxxxxxx and xxxxxxxx8. If we pick 00000008 = xxxxxxxx for the first string and 80000000 = xxxxxxxx for the second, we have the same string 800000008 obtained, but my counting method above counts these as separate strings since the "filled-in" part was different. This is why the erroneous answer is far larger than the actual one.

2

It is true that your 2nd approach, as it is stated in the posted question, is erroneous. It is also true that the error is as stated in your answer: you are over-counting. However, your 2nd approach can be repaired through the use of Inclusion-Exclusion. See this article for an introduction to Inclusion-Exclusion. Then, see this answer for an explanation of and justification for the Inclusion-Exclusion formula.

Let $~S~$ denote the set of all possible $~9~$ digit numbers, without any regard for whether the number contains an $~8~$ anywhere in its digits. For $~k \in \{1,2,\cdots,9\},~$ let $~S_k~$ denote the subset of $~S~$ that specifically contains an $~8~$ in digit position 1 (where the digit positions read from left to right).

For example, an element in $~S_1~$ would be any number that contains an $~8~$ in digit position 1. Such an element may or may not contain an $~8~$ in some other digit position.

Then, the desired enumeration is

$$|S_1 \cup S_2 \cup \cdots \cup S_9|. \tag1 $$

Let $~T_1~$ denote $\displaystyle \sum_{1 \leq i_1 \leq 9} S_{i_1}.~$

That is, $~T_1~$ denotes the sum of $~\displaystyle \binom{9}{1}~$ terms.

By considerations of symmetry, you have that $~|S_1| = |S_2| = \cdots = |S_9|.$

Therefore, $~T_1 = 9 \times |S_1| = 9 \times (10)^{(9-1)}.$


Similarly, for $~r \in \{2,3,\cdots,9\},~$

let $~T_r~$ denote $~\displaystyle \sum_{1 \leq i_1 < i_2 < \cdots < i_r \leq 9} | ~S_{i_1} \cap S_{i_2} \cap \cdots \cap S_{i_r} ~|.$

That is, $~T_r~$ denotes the sum of $~\displaystyle \binom{9}{r}~$ terms.

Then, by similar considerations of symmetry, you have that

$$T_r = \binom{9}{r} \times (10)^{(9-r)}.$$

By Inclusion-Theory, the computation in (1) above is equivalent to

$$\sum_{r=1}^9 (-1)^{(r+1)} T_r$$

$$= \sum_{r=1}^9 (-1)^{(r+1)} \left[ ~\binom{9}{r} \times (10)^{9-r}~\right]. \tag2 $$

The expression in (2) above is in fact equivalent to $~(10)^9 - 9^9.$

This can be demonstrated by taking the binomial expansion of $~9^9 = (10 - 1)^9.$

$$9^9 = (10 - 1)^9 = \sum_{r = 0}^9 \left[ ~\binom{9}{r} (10)^{(9-r)} (-1)^r ~\right] \implies $$

$$10^9 - 9^9 = \sum_{r = 1}^9 \left[ ~\binom{9}{r} (10)^{(9-r)} (-1)^{(r + 1)} ~\right].$$


$~\underline{\text{Addendum}}$

Still another approach is to reason that if a 9 digit number has at least one 8, then it must have exactly $~k~$ 8's, where $~k~$ is some element in $~\{1,2,\cdots,9\}.$

So, you have the mutually exclusive possibilities, based on the value of $~k,~$ where the enumeration of 9 digit numbers with exactly $~k~$ 8's is

$$\binom{9}{k} 9^{(9-k)}.$$

Therefore, you have an alternate computation of

$$\sum_{k=1}^9 \left[ ~\binom{9}{k} 9^{(9-k)} ~\right]. \tag3 $$

The expression in (3) above can also be demonstrated to be equivalent to $~(10)^9 - 9^9,~$ by taking the binomial expansion of $~(10)^9 = (9 + 1)^9.$

$$(10)^9 = (9 + 1)^9 = \sum_{k = 0}^9 \left[ ~\binom{9}{k} 9^{(9-k)} 1^k ~\right] \implies $$

$$10^9 - 9^9 = \sum_{k = 1}^9 \left[ ~\binom{9}{k} 9^{(9-k)} ~\right].$$

user2661923
  • 42,303
  • 3
  • 21
  • 46