# What is the probability that an integer between 0 and 9,999 has exactly one 8 and one 9?

I Googled this question and found some answers but they were all different from each other, so I don't know which one is correct.

Question: What is the probability that an integer between 0 and 9,999 has exactly one 8 and one 9?

I tried by splitting it into 3 cases.

Case #1 (2 digits): 98 or 89, so only 2!=2 possible ways of arranging 2 digits.

Case #2 (3 digits): One possible outcome is 98y where y can be integers from 0 to 7 (so there's 8 possible values for y). 3!=6 ways of arranging it. So there's 6*8-2 = 46 possible 3 digit numbers. I subtracted 2 from it because 098 and 089 are not 3 digit numbers.

Case #3 (4 digits): A possible outcome is 98xy where x and y can both take on 8 possible values ranging from 0 to 7. 4!/2! = 12 ways of arranging it because if x=y, 98xy is the same as 98yx. So we have: 12*8*8-48 = 720 possible 4 digit numbers. 48 is the result of 46 + 2 from case #2 because we have to subtract outcomes where the first two digits are 0 or the first digit is a 0 eg: 0098.

Therefore, the total is 2 + 46 + 720 = 768 numbers with exactly 8 and 9 in it. The probability is 768/10000.

• Note that if you allow the four digit numbers to have leading zeroes (i.e. allow numbers like $0098$), then that takes care of two- and three-digit numbers automatically, without having to treat those as a special case, and without having to treat $0$ as a special digit. – Arthur Jan 22 '16 at 21:20
• Your result is correct. It is a much harder approach than the answers, but you were careful to get them all and once each. – Ross Millikan Jan 22 '16 at 21:29
• leading zeros are allowed because associating strictly 4 digit numbers with leading zeros allowed with the corresponding 1, 2, 3 or 4 digit numbers without leading zeros is a 1-1 association. e.g. 0071 ~ 71 and nothing else. ... or another way of putting it 0071 and 71 are simply two different ways of writing the same thing. And as the two answers show, using leading zeros makes the calculations much easier. – fleablood Jan 22 '16 at 21:45

Let us ask the related question of how many 4-digit strings have exactly one eight and one nine. (Strings are allowed to have leading zeroes, whereas numbers are not) Note that the 4-digit strings are in direct bijection with the integers from $0$ to $9999$.
• Pick the location of the nine ($4$ choices)
• Pick the location of the eight (It can't be where the nine is, so $3$ choices)
• For each remaining position, pick a digit other than eight or nine ($8$ choices each time for a total of $8\cdot 8$ choices)
Thus, the number of four-digit strings with exactly one eight and one nine is $4\cdot 3\cdot 8\cdot 8$
Since there are $10^4$ different four-digit strings regardless, the probability is then $\dfrac{4\cdot 3\cdot 8\cdot 8}{10^4} = \dfrac{768}{10000} = .0768$
If you make all your numbers four digits by allowing leading zeros it is easier. You have four places to put the $9$, then three left to put the $8$, then $8$ choices for each of the other two places. $4 \cdot 3 \cdot 8^2=768$ good numbers out of $10000$, so the probability is $0.0768$