[Math] the probability that an integer between 0 and 9,999 has exactly one 8 and one 9

combinatorics

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.

Best Answer

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$