# Number of ways to construct a 4 digit pin code, under some conditions

Given the digits $$0,1,...,9$$, the numer of possibilities to construct a PIN code is $$10^4$$ (zero can be at the beginning since it's a code and not a number).

I need to find the number of PIN codes that have at least two of the same digits.

I tried using two ways to calculate, but got different results and I could really use some help figuring out why it happend.

First solution:

The number of PIN codes with all distinct digits is $$10\times9\times8\times7$$. So the number of PIN codes with at least two of the same digits should be $$10^4 - 10\times9\times8\times7 = 4960$$.

Second solution:

If a PIN code has at least two of the same digits, it has exactly two, three or four of the same digits.

For having exactly two of the same digits, I have $$10$$ choices for what digits should be the same. I then choose their position in the code, $${4 \choose 2}$$ choices for that , and then there are $$9\times8$$ choices for the other two digits. All in all, there are $$10\times{4 \choose 2}\times8\times9=4320$$ possibilities for that.

For having exactly three of the same digits, again there are $$10$$ choices for what digits should be the same. For choosing their position in the code there are $${4 \choose 3}$$ ways, and $$9$$ ways to pick the fourth digit. So there are $$10\times{4 \choose 3}\times9 = 360$$ possibilities for that.

Lastly, the number of possible ways to construct a PIN code with exactly 4 of the same digits is $$10$$, which is trivial $$(0000,1111,...,9999)$$.

Summing up all of the above, we get that the number of possibilities is $$4320+360+10 = 4690$$.

I could really use some help figuring out why one (or both) of my methods is wrong.

Thanks!

• Doesn't $0000$ have only one distinct digit? You have totally misinterpreted the question. Jan 6, 2021 at 16:15
• Hi, my apologies, since English is not my main language I totally misinterpreted the meaning of the word distinct. I edited it, hope it makes sence now. Jan 6, 2021 at 16:23
• You missed the case where you have two pairs, for example 1122 or 3443. Jan 6, 2021 at 16:26
• No pairs give you $270$ and not $540$. You are double counting. Jan 6, 2021 at 17:14
• Say you choose $1$ and the next number is $2$. Your $4C2$ will count 1 2 1 2, 2 1 2 1 and so on. Now when the first number is $2$ and the next number is $1$, you again count them. Jan 6, 2021 at 17:19

We have $$10\times9$$ choices for the two pairs of identical digits. Next, we need to find out how many possibilities are there to divide them to pairs. This is much like dividng $$2n$$ people to pairs, when $$n=2$$.
All in all we get: $$10\times9\times\frac{4!}{2^{2}\times2!} = 270$$.
Summing this with the above we get $$270+4690=4960$$, which is the correct answer.