A friend and I recently talked about this problem:
Say my friend feels a little adventurous and tells me that exactly three of four digits of his PIN-code are the same, what is the probability that I will guess it in three tries?
At first I thought this shouldn't be too difficult to count, but the digit restriction threw me off. Essentially I want to count how many possible PIN-codes there are with the restriction that $3$ of $4$ digits are the same. I tried thinking in terms of using sums, but I got stuck. I actually ended up making a quick MATLAB-script that computed the number of possible PIN-codes using a brute force method. Assuming that my script is correct there are $360$ codes that abide by this restriction out of a total of $10^4=10\hspace{4 px}000$ possible PIN-codes. Using this it is easy to calculate the rest, but I am now wondering how one might go about this in a more elegant way.
A PIN-code is a $4$-digit number where the possible digits are $0,1,2,...,9$. So for my question two examples of possible codes are $3383$ and $2999$. Let's assume that there are no further restrictions, although in reality there likely are, and that each digit is equally likely. It is important to note that I do not know if it is $0,1,...,8$, or $9$ that appears three times.
This question is not homework or anything, it is really just for curiosity. Thanks for any help!
(By the way I saw this question: Combinatorics and Probability Problem but it did not help me.) EDIT: I made an error in my script. Updated.