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?


1 Answer 1


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.

  • $\begingroup$ 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). $\endgroup$
    – Hopper
    Oct 6, 2019 at 23:28
  • $\begingroup$ @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. $\endgroup$ Oct 6, 2019 at 23:35
  • $\begingroup$ @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)$ $\endgroup$
    – Hopper
    Oct 6, 2019 at 23:37
  • $\begingroup$ Never-mind, I see where there exists the double counting. $\endgroup$
    – Hopper
    Oct 6, 2019 at 23:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .