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!