[Math] Number of $ 6 $ Digit Numbers with Alphabet $ \left\{ 1, 2, 3, 4 \right\} $ with Each Digit of the Alphabet Appearing at Least Once

combinationscombinatoricspermutations

Find the number of 6 digit numbers that can be made with the digits 1,2,3,4 if all the digits are to appear in the number at least once.

This is what I did –

I fixed four of the digits to be 1,2,3,4 .
Now remaining 2 places can be filled with 4 digits each. Number of 6 digit numbers if two places are filled with same digit are 4 * 6!/3! and if filled by different digits are 12 * 6!/(2!*2!). Therefore, total such numbers are 2880.

But the correct answer is 1560.

Any hint would be appreciated.

Best Answer

Instead of dividing into cases, we use the Principle of Inclusion/Exclusion.

There are $4^6$ strings of length $6$ over our $4$-letter alphabet. Now we count the bad strings, in which one or more digits are missing.

There are $3^6$ strings with the digit $1$ mising, and also $3^6$ with $2$ missing, with $3$ missing, with $4$ missing.

So our first estimate for the number of bad strings is $4\cdot 3^6$.

However, when we added, we multiply counted the bad strings that have more than one missing digit. For example, there are $2^6$ strings with $1$ and $2$ missing, and the same for all $6$ ways to choose $2$ digits from $4$.

So our next estimate for the number of bad strings is $4\cdot 3^6-6\cdot 2^6$.

However, we have subtracted too much, for we have subtracted one too many times the $4$ strings with $3$ digits missing. So the number of bads is $4\cdot 3^6-6\cdot 2^6+4$.

More neatly, we can write the number of good strings as $$\binom{4}{0}4^6-\binom{4}{1}3^6+\binom{4}{2}2^6-\binom{4}{3}1^6.$$

The method readily generalizes.