4-digit numbers with two of the same digit

combinatorics

How many 4-digit numbers (including leading zeros) have exactly one digit appearing twice?

Here's what I thought:

There are $\binom{4}{2,1,1} = 6$ digit "layouts", with $c$ as the repeated digit: $abcc, bacc, accb, bcca, ccab, ccba$

Then there are $10 \times 9 \times 8$ ways to assign digits $0$ thru $9$ to $a, b, c$.

I also thought that this would over-count strings where $a$ and $b$ are swapped, for example $abcc$ and $bacc$. To check I wrote some code and apparently it isn't over-counted. I think I am missing something simple – the way I assigned digits to $a, b, c$ means I can't over-count layout $abcc$ with $a=1, b=2$, and layout $bacc$ with $a=2, b=1$? This should be simple but I am confusing myself.

Best Answer

Here’s one way to solve the problem, which you’ll recognize as essentially the same as yours.

Start by selecting the two places that will hold the same digit (in any of $4\choose 2$ ways). For each of those pairs of places, select which digit to put there (in any of $10\choose 1$ ways). For each of those placements of a digit in two places, select the digit to put in the leftmost still-empty place (in any of $9 \choose 1$ ways). For each of those fillings of three spaces with exactly two digits, select which digit to put in the last still-empty place (in any of $8 \choose 1$ ways).

So the 4-digit numbers fitting your specifications number $${4 \choose 2}{10\choose 1}{9\choose 1}{8\choose 1} = 4320$$ ways.