Your progress is barred by a locked door, it is clearly controlled by a keypad. with 10 digits (0-9) plus a button for ENTER and a button for CANCEL. You know several things about this lock:

  • This keypad combination lock uses 4 digit code, no more than 4 digits, no less.
  • If you enter the wrong code 3 times in a row then the alarm sounds and it locks down.
  • There is no timeout on the wrong tries, the third wrong input sounds the alarm and it locks down no matter how long you delay.
  • The lock has a tamper proof design, any attempt to disassemble or break open the lock (with the skills and tools you have available) will sound the alarm and locks down.

Looking more carefully at the keypad you notice that there is a thin film of dust and grim over the whole surface, except 4 keys:

4, 7, 9 and ENTER

Those keys have the numbers/letters on them slightly chipped and the faint outline of fingerprints.

You press one of the numbers, it makes a short high pitched BEEP noise. In response to this noise there is a loud sneeze from behind you, you look to see there is a man sleeping in an alcove near the door, he is clearly homeless and living on the streets.

You strike up conversation with the man, whose name is Alex, and he says he has been staying here for a few nights and has seen the door be used.

You: "Can you tell me what the pass code is?"

Alex: "No, but I can give you a clue: The digital sum of the code is also the digital sum of the factorial of the fifth prime."

You: "..."

Alex: "AH HA HA HA! The look on your face! How could I know some tangential mathematical trivia of the passcode without knowing the code? Nah, I just heard the beeps"

You check the keypad, all the keys on the pad have the exact same tone, except the ENTER key that makes a low pitched BWRRRT.

Alex: "yeah, I only heard the rate they were pressed; Beep ... Beep-beep ... Beep... then a BWRRT."

You know that the chance of entering the correct code by a single lucky guess is 1 in 10'000. You're not willing to risk it for odds that slim... how could you have better odds, say, 50% chance of opening the door?

Which number or numbers should you try to enter?

How can you be sure of the odds?

  • 1
    $\begingroup$ do we still have 3 try? because it seems we have press ENTER once (to know how it sounds like). $\endgroup$
    – Untitpoi
    Commented Feb 15, 2018 at 12:52
  • 1
    $\begingroup$ Wouldn't a lucky guess be 1 in 81, since you know it's limited to three specific numbers? (actually even less than that, since you know one number is used twice and the others used only once each). $\endgroup$
    – sirjonsnow
    Commented Feb 15, 2018 at 14:43
  • $\begingroup$ A SINGLE lucky guess if they didn't realise it was limited to those 3 digits. $\endgroup$
    – TREB
    Commented Feb 16, 2018 at 1:46

2 Answers 2


It sounds like the code is one of the following



The wear on the digits 4, 7 and 9 suggests that they are the only ones used in the code and that they are all used at least once. Also the pattern of beeps heard by Alex suggests the second and third digit are the same.

So the strategy could be

Try three of those, that should give you a 50% success rate.

  • $\begingroup$ If - by some chance - the math trivia is actually true, then 4 of these codes can be excluded. $\endgroup$
    – elias
    Commented Feb 15, 2018 at 11:42
  • 2
    $\begingroup$ Is that true? I get the digital sum of 11! as 36 which does not match any of them. In fact, there is just one code that this could match and the other clues don't suggest to me that this is the case. $\endgroup$
    – hexomino
    Commented Feb 15, 2018 at 11:57
  • $\begingroup$ sorry, for some reason I thought the fifth prime number is 13. maybe I was indexing my array from 0 :D $\endgroup$
    – elias
    Commented Feb 15, 2018 at 11:59
  • 4
    $\begingroup$ To me the story strongly suggests that the math trivia bit is just a joke, and is not meant seriously. The fact that this solution gets you to a 50% chance, and that's the chance OP specifically mentioned in the question makes me think it's right as it is. $\endgroup$
    – Tom
    Commented Feb 15, 2018 at 12:54

I think the answer is 4779 or 9774.


The digital sum of the 5th factorial is 11! = 9, not 36 since you must then add 3+6.

The only possible combinations to get 9 as digital sum I can get is 4,7,7,9, therefore 7 must be the numer repeating, leading to only two possible solutions. You can check both and open the door

  • $\begingroup$ I think that is generally called the digital root rather than digital sum. $\endgroup$
    – hexomino
    Commented Feb 15, 2018 at 12:15
  • $\begingroup$ oh, I always thought digital sum was all the way till the end... $\endgroup$ Commented Feb 15, 2018 at 12:20
  • $\begingroup$ I'm guessing that when Alex says "digital sum" he means digital root. (The sum of the digits would more often be called "the sum of the digits" or maybe the "digit sum", so "digital sum" doesn't quite match usual practice either way.) $\endgroup$
    – Gareth McCaughan
    Commented Feb 15, 2018 at 12:40
  • 1
    $\begingroup$ So you're assuming Alex know the code and is lying when he said his hint is false. $\endgroup$
    – Untitpoi
    Commented Feb 15, 2018 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.