How many numeric strings of length 8 have exactly three 3’s or have exactly 2 digits

combinatorics

I've been practising some combinatorics questions but am finding this one a bit difficult.

I recognise that we can split the question into 2 i.e.

  • Find how many strings have three 3's
  • Find how many strings have exactly 2 digits
  • Add the totals together

My initial approach for the first part was to essentially remove 3 characters from the string (these represent the three 3's) and then remove the digit 3 from the selectable digits.

I'm using the formula $\binom{n + k -1}{k – 1}$ for this so $\binom{5 + 9 – 1}{9 – 1} = 1287$ but I feel like this is the incorrect approach.

For the second part, I believe we can just do $$\binom {10}{2} = 45$$

If these totals were correct, I would expect the final total to be $1287 + 45 = 1332$ but again I feel like my calculation for the first part is incorrect.

Best Answer

Strings of $8$ digits with exactly $3\ 3$s are ${8 \choose 3}9^5$ because you choose the places for the $3$s and then the rest can be any digit.

Strings with exactly two digits are ${10 \choose 2}(2^8-2)$ because you choose the two digits, then each position has to be one of the two, but you can't allow all of them the be the same.

Now you have counted the ones with three $3$s and five of something else twice, so subtract them once and the result is

$${8 \choose 3}9^5+{10 \choose 2}(2^8-2)-{8 \choose 3}9$$