How many five digit numbers can be formed from the integers 1,2,..,9 with one digit appearing at max thrice?

324 Views Asked by At

The problem is in the title of the question, repeated below:

How many five digit numbers can be formed from the integers 1,2,..,9 with one digit appearing at max thrice?

I have two solutions as below but they give different counts. Does solution 1 counts some numbers multiple times? Or does solution 2 miss to count certain numbers? I am not able to find the reason for the gap between two counts.

Solution 1

It should be the sum of following:
(1) No digit repeating: ${}^9P_5$
(2) One digit repeating twice: $9\times {}^5C_2\times 8\times 7\times 6$
(3) Two digits repeating twice: $9\times 8\times {}^5C_2\times {}^3C_2\times 7$
(4) One repeating thrice and others not repeating: $9\times {}^5C_3\times 8\times 7$
(5) One repeating thrice and other twice: $9\times {}^5C_3\times 8$
Sum of (1) to (5) is $66240$


Solution 2

Total numbers $= 9^5$
Unwanted numbers:

  • All same digits = 9 ways (11111,22222... 99999)
  • 4 digits same $= 9 \times ({}^5C_4 \times 8)$
    For example,
    four 1's: ${}^5C_4 \times 8$ ways,
    four 2's: again ${}^5C_4 \times 8$ ways
    Hence for 9 such cases $9 \times ({}^5C_4 \times 8)$ ways

Hence Ans $= 9^5 - (72 * {}^5C_4) - 9=49968$