# How many ways are there to pick a lock?

A passenger left his belongings inside a locker at an airport. When he wanted to get his belongings, it turned out that he forgot the number. He only remembers that it has numbers $$23$$ and $$37$$ in it. In order to open the locker, he needs to enter a $$5$$-digit number. What is the minimal number of numbers that he will need to try to be able to open the locker?

So, we have $$2$$ cases:

• $$a = 23, b = 37, c \in \{0,...,9\}$$, this gives us $$1\times 1\times 10\times 3!=60$$ ways.
• $$a = 237, b \in \{0,...,9\}, c \in \{0,...,9\}$$, this gives us $$1\times 10\times 10\times 3!=600$$ ways. And the final answer is $$660$$. But the author says it's $$360$$, are they wrong, or am I wrong? (The book has mistakes in the answer section...)
• The case $23237$ has been counted in both your cases, as has $23723$, $37237$ and $23737$. It wouldn't surprise me if the rest are also from this kind of overcounting, but it's late and I'm too tired to look for them. Oct 11, 2018 at 21:56
• @Arthur thanks! Oct 11, 2018 at 21:57
• A brute force simulation gives $356$.
– Jens
Oct 11, 2018 at 22:23
• @Arthur you have described all of them, there are no other ones. The answer is $356$. In my question I didn't count the second case correctly, it should be $1\times 10\times 10\times {3 \choose 1} = 300$, and I wrote $1\times 10\times 10 \times 3!=600$, so all in all, we get $300+60-4=356$. The book's answer is $360$ because the author forgot to subtract $4$. Oct 12, 2018 at 10:26

Since your way of thinking the problem as two cases is correct, I will give a hint:

HINT: Notice that in your first case, you have counted the case $$c = 7$$ and the pass-code can be $$abc$$, that is $$23737$$, which is also counted in your second case.

Also, in your second case, for $$b = 3$$, $$c = 7$$, there are some cases like $$abc = 23737$$, $$bca = 37237$$, which are already counted in the first part.

There might be some similar overcounted cases so can you revise your calculations now?

• The first case has only 60 numbers, and the total number of overcounts is 300. So, there are cases that you haven't described (I think, or maybe somethings are overcounted more than once, which is hard to reason about for me). I will look at this tomorrow (because it's late and I can't think) and let you know, thanks! :) Oct 11, 2018 at 22:13
• Yes, I did not describe all the cases since you got the idea and can find the other ones yourself :) Oct 12, 2018 at 9:56
• The answer is 356, i think the second case should be 1*10*10*3 instead of 1*10*10*3!. So you get 300 + 60 - 4. So, the author of the book forgot to subtract 4. Oct 12, 2018 at 10:09
• ideone.com/rc7wyQ Oct 12, 2018 at 10:17
• Nice code and verification, well done :) Oct 12, 2018 at 10:20