Combinatorics – Should a 4-Digit Pin Code Have Repeated Digits

combinatorics

A small argument my colleague and I were having…

Say I've got a $4$-digit security code on my burglar alarm, and I'm too lazy to ever change it. Over time, the digits involved will become worn.

If I've used $4$ different digits (as is common, eg $1357$), then an attacker, knowing those are the digits in the code, needs (if I'm right!) $24$ goes to try all combinations.

If I've repeated a digit (eg, $1317$), the attacker just knows $1$, $3$ and $7$ are used (assume that all wearing is indistinguishable). How many different possible $4$-digit codes are possible, using each digit at least once? I say it's more than $24$, my colleague is convinced otherwise.

Bonus kudos for generalizing the problem to knowing $k$ digits in an $n$-digit pin. 😉

Best Answer

If the burglar knows which digit is repeated, (s)he has \begin{equation*} \dfrac{4!}{2!} = 12 \end{equation*} codes to try. Since (s)he doesn't know which digit is repeated, (s)he will have to try $3 \cdot 12=36$ different codes.