[Math] 3 digits for a 4 digit pin code

combinatorics

I see that some very similar questions have been answered, perhaps some more general answer contains my question.

I was asked how many combinations there would be if exactly 3 digits are used for a 4 digit pin code.
I reasoned in the following way but I am not completely sure I have thought of everything. Rather than taking the combinations in order of appearance (which I initially tried to but failed) I looked at the doublets:

Any combination will contain one number doubled since all three digits must be used. The doublets can occur for a number of combinations, like the lines of the sides in a square with number of diagonals added, i.e. in 6 ways. The 3 doublets (1,1) (2,2) and (3,3) arranged in 6 ways allows for 18 combinations.

For everyone of these the remaining two digits can be arranged I 2 ways such as for example after the doublet (1,1) must come (2,3) and (3,2). This gives me 2*18=36 combinations.

Does this look reasonable to you?

Best Answer

One way to count those pin codes:

First choose the digit to use doubly, this an be done in $10$ ways ($0$ to $9$).

Then choose the $2$ positions out of $4$ to put those in, there are $\binom{4}{2} = 6$ ways for that.

Now fill the two remaining positions left to right from the $9$ remaining digits in $9 \times 8$ ways.

So in total I get $10\times 9 \times 8 \times 6 = 4320$ pin codes with exactly three distinct digits. Confirmed by a simple Python script.

If you already know the three digits that are being used, the same way yields $\binom{4}{2} \times 3! = 36$ ways, as your answer initially was.

Related Question