# Total Number of $4$ Digit Codes with Repeated Digits

Suppose I have a 4 digit code that I can make with the 10 digits, repetition allowed. I want to find the total number of codes that have repeated digits. The easiest way would be Total Possible Codes $$-$$ Non-repeating Digit Codes -> $$10^4 - (10 \times 9 \times 8 \times 7)$$.

But suppose I want to do a case by case basis looking for the codes with repeating digits. For codes with 2 repeating digits I first find total combinations of $$2$$ slots out of the $$4$$, assign them a digit, then assign the remaining two digits. I get : $$4 \choose 2$$ $$(10 \times 9 \times 8)$$

Similarly with 3 repeated digits I get $$4 \choose 3$$ $$(10 \times 9)$$ and 4 repeating digits $$4 \choose 4$$ (10). But adding these up gives a different result than doing it using the first method. Why is this? What am I doing wrong?

You overlooked codes with two different digits repeated twice, such as 1122. The number of these is $$\binom{10}{2}\binom 42=270$$. Adding this should balance the scales.
• Ah okay. Why don't we get $4 \choose 2$ $(10 \times 9)$? Since we have 4 slots and we are choosing two, assigning them one of 10 digits (10 options), then assigning the remaining two slots the same digit (9 options then 1 option). Oct 6 '19 at 23:28
• @krauser126 There are $\binom{10}{2}$ ways to choose which two numbers to use in the string and $\binom{4}{2}$ ways to choose the positions of the smaller of these numbers. Once those choices are made, the string is completely determined since the other two positions must be filled with the larger of the selected numbers. Oct 6 '19 at 23:35
• @N.F.Taussig But why isn't it correct to do it the other way? There are $4 \choose 2$ ways of selecting slots for the first pair of repeated digits. There are $10$ ways of selecting the digit for that pair. There are $9$ ways of selecting the digit for the remaining pair and it's order is also determined so there are $1$ ways of ordering it. $4 \choose 2$ $(10 \times 9)$ Oct 6 '19 at 23:37