I found this problem in a contest of years ago, but I'm not very good at probability, so I prefer to see how you do it:

A man gets drunk half of the days of a month. To open his house, he has a set of keys with $5$ keys that are all very similar, and only one key lets him enter his house. Even when he arrives sober he doesn't know which key is the correct one, so he tries them one by one until he chooses the correct key. When he's drunk, he also tries the keys one by one, but he can't distinguish which keys he has tried before, so he may repeat the same key.

One day we saw that he opened the door on his third try.

What is the probability that he was drunk that day?

  • 5,340
  • 1
  • 18
  • 43
  • 4
    This seems like a fun problem. To start we know .5 is the probability he is drunk and sober. There is a 20% chance he randomly chooses the right keys, but when hes drunk he may use the same key more than once (makes it a bit tougher). He opens on the third try. I'm thinking of something along the lines of finding P(Drunk | opens door on third try) – Brandon Dec 04 '16 at 21:45
  • @Brandon "I'm thinking of something along the lines of finding P(Drunk | opens door on third try)" is just restating the question. The question asks you to find P(Drunk | opens door on third try), it just doesn't use that notation. – user253751 Dec 04 '16 at 22:58
  • 5
    Oh trust me I know that, I was just laying out a guideline for the OP, rather than solving it for him explicitly like a few people did below. – Brandon Dec 04 '16 at 23:14
  • Out of curiosity, what kind of contest was that? Although it's a fun problem it seems kind of easy for a contest math problem – user159517 Dec 07 '16 at 16:54
  • Is the second part of a contest, where the students solve it in a board, but they have 5 minutes or less to solve it. – iam_agf Dec 07 '16 at 18:07
  • Btw, the first part is a test of three hours. From that test they select the twenty best scores. – iam_agf Dec 08 '16 at 01:13
  • I was thinking the number of ways he can use the set of keys drunk which means various ways of repeating , example key 1 used 2 times, key4 used 3 times ect , labeling keys 1-5 and number of times 1-3 , then dividing this by Total number of ways drunk & sober – Randin Mar 02 '18 at 10:25

5 Answers5


The key thing here is this: let $T$ be the number of tries it takes him to open the door. Let $D$ be the event that the man is drunk. Then $$ P(D\mid T=3)=\frac{P(T=3, D)}{P(T=3)}. $$ Now, the event that it takes three tries to open the door can be decomposed as $$ P(T=3)=P(T=3\mid D)\cdot P(D)+P(T=3\mid \neg D)\cdot P(\neg D). $$ By assumption, $P(D)=P(\neg D)=\frac{1}{2}$. So, we just need to compute the probability of requiring three attempts when drunk and when sober.

When he's sober, it takes three tries precisely when he chooses a wrong key, followed by a different wrong key, followed by the right key; the probability of doing this is $$ P(T=3\mid \neg D)=\frac{4}{5}\cdot\frac{3}{4}\cdot\frac{1}{3}=\frac{1}{5}. $$

When he's drunk, it is $$ P(T=3\mid D)=\frac{4}{5}\cdot\frac{4}{5}\cdot\frac{1}{5}=\frac{16}{125}. $$

So, all told, $$ P(T=3)=\frac{16}{125}\cdot\frac{1}{2}+\frac{1}{5}\cdot\frac{1}{2}=\frac{41}{250}. $$ Finally, $$ P(T=3, D)=P(T=3\mid D)\cdot P(D)=\frac{16}{125}\cdot\frac{1}{2}=\frac{16}{250} $$ (intentionally left unsimplified). So, we get $$ P(D\mid T=3)=\frac{\frac{16}{250}}{\frac{41}{250}}=\frac{16}{41}. $$

Nick Peterson
  • 31,127
  • 2
  • 52
  • 72

Let's first compute the probability that he wins on the third try in each of the two cases:

Sober: The key has to be one of the (ordered) five, with equal probability for each, so $p_{sober}=p_s=\frac 15$.

Drunk: Success on any trial has probability $\frac 15$. To win on the third means he fails twice then succeeds, so $p_{drunk}=p_d=\frac 45\times \frac 45 \times \frac 15 = \frac {16}{125}$

Since our prior was $\frac 12$ the new estimate for the probability is $$\frac {.5\times p_d}{.5p_d+.5p_s}=\frac {16}{41}=.\overline {39024}$$

  • 62,572
  • 4
  • 66
  • 113
  • What is the last formula you used? – Ovi Dec 05 '16 at 04:21
  • 7
    @Ovi It is [Bayes theorem](https://en.wikipedia.org/wiki/Bayes'_theorem). – Shadow Dec 05 '16 at 05:21
  • 2
    Using this method, the probability that he is drunk will *decrease* if he succeeds at finding the right key at a *later* try (I get 50%, 44%, 39%, 34%, 29% for tries number 1, 2, 3, 4, 5 being correct). This seems inplausible. Where is the flaw? – mkrieger1 Dec 05 '16 at 14:15
  • 1
    @mkrieger1 That result seems entirely intuitive to me (though it's worth point out that if it takes more than $5$ tries then the probability jumps to $1$). For intuition, suppose that you have $2\times 10^5$ people doing this independently. Then, in expectation, you have $100000$ sober and $100000$ drunk. Of these, we expect $20000$ of the sober ones to take five tries, but only $8192$ of the drunk ones will win on the fifth trial. Thus we expect $28192$ of the original sample to win on the fifth trial, but the great majority of these are sober. – lulu Dec 05 '16 at 14:26
  • @mkrieger1 Should have said: I agree with your calculations. Indeed, $\frac {8192}{28192}=0.290578888$. – lulu Dec 05 '16 at 14:27
  • 2
    @lulu That sounds convincing, altough it is still not intuitive to *me*. Another example of how humans are sometimes bad at judging probabilities. – mkrieger1 Dec 05 '16 at 14:31
  • 10
    @mkrieger1 Oh, agreed. Perhaps it helps to keep in mind that $41\%$ of the time, our drunk needs more than five trials. That's a huge number! Thus, the mere fact that the man succeeds in the first five trials is strong evidence for his sobriety. – lulu Dec 05 '16 at 14:37
  • 2
    +1. So going frequentist and increasing the number of keys to $100$, if the null hypothesis is that he is sober and the alternative hypothesis is that he is drunk, an optimal $95\%$ test would reject the null hypothesis if he uses more than $100$ key attempts *or if he uses fewer than $6$ attempts* – Henry Dec 06 '16 at 00:33
  • 1
    Perhaps your intuition will be appeased if we note that, in expectation, it takes the sober person 3 tries ($(n+1)/2$ if there are $n$ keys) and the drunk person 5 tries ($n$ tries, for $n$ keys). Or perhaps not - it appeases my intuition, but intuitions are funny that way. – Michael Lugo Dec 07 '16 at 14:35

I tried focusing instead on the number of times he tries a key and fails. So if he gets it on the 3rd try, he misses $2x$. The probability of doing this, given that he's drunk, is $(4/5) * (4/5) = 16/25$. On the other hand, the probability of him missing twice in a row given that he's sober is $(4/5) * (3/4) = 3/5$. Applying Baye's rule, I get

$$Pr(\text{drunk}\mid \text{missed twice}) = (16/25)/((16/25 + (3/4)(4/5)) = 0.51$$

Given that he misses $3x$, I get

$$Pr(\text{drunk}\mid \text{missed }3x) = ((4/5)^3)/((4/5)^3 + (2/3)(3/4)(4/5)) = 0.62$$

$$Pr(\text{drunk}\mid \text{missed }4x) = ((4/5)^4)/((4/5)^4 + (1/2)(2/3)(3/4)(4/5)) = 67.2$$

$$Pr(\text{drunk}\mid \text{missed } 5x) = ((4/5)^5)/((4/5)^5 + 0) = 1$$

The result has the desirable property that the probability starts at $0.5$ and gets higher the more we observe he starts missing the lock. I'm thinking the success on the $x$ attempt should not enter the calculation. I justify this because, we're given the observation that he finally opens the door, so that's not part of our probability calculation. What's really uncertain is the number of times he has to try before he opens it.

  • 5,340
  • 1
  • 18
  • 43
  • 1
    What you have is the probabilities that he misses **at least** twice before he finds the right key, but you need the probabilities that he misses **exactly twice** before finding the right key. – Daniel Fischer Dec 07 '16 at 16:58
  • Could you please explain? I have – user3159090 Dec 07 '16 at 17:46
  • I have Pr(misses 2x) = Pr(misses on 2nd | misses on 1st) x Pr(misses on 1st). For drunk, this is 4/5 * 4/5. For sober, this is 4/5 * 3/4, no? – user3159090 Dec 07 '16 at 17:48
  • This should be equal to Pr(misses on 1st, 2nd, 3r) + Pr(misses on 1st, 2nd, but opens on 3rd) – user3159090 Dec 07 '16 at 17:50
  • You have the probability that the first two tries are misses (for drunk and for sober), but these don't say what happens after that, whether the third try is successful or not. You need the probabilities for "the first two tries are misses, and the third is successful". – Daniel Fischer Dec 07 '16 at 18:25
  • So if you calculate the probability that the first two are misses and the third is successful, you get something like 0.39, as in the answers above. This can't be plausible. How could we start by saying he's 50% likely to be drunk and conclude, after observing 2 failures followed by a success, that he's now only 39% likely to be drunk? As someone mentioned above - it only gets worse from there. If you now observe 3 failures followed by a success, and you use this calculation, he gets even less likely to be drunk. In short, failure should add to the probability he's drunk, not lower it. – user3159090 Dec 07 '16 at 20:31
  • 1
    As I said in an earlier comment: suppose you had $2\times 10^5$ people doing this, so $10^5$ sober and $10^5$ drunk. Of course $20000$ of the sober people succeed on the first try, and on the second, and so on. Similarly, $20000$ drunks succeed on the first try...hence succeeding on the first try tells us nothing about sobriety. But only $16000$ drunks succeed on the second try, so success on the second try suggests sobriety. And then only $12800$ drunks succeed on trial three, so the evidence for sobriety is even stronger. Keep in mind that $5$ failures does prove drunkenness. – lulu Dec 08 '16 at 21:56
  • I guess that makes sense, thanks Lulu. So the reason a success on the 3rd attempt seems to indicate sobriety is that the drunkards are getting pushed out towards > 5 attempts. – user3159090 Dec 13 '16 at 15:39

I'll do it for the case where the man has $k$ keys and gets the correct key on the $j$th try. Essentially, we're trying to find

$$P(\text{Drunk|$j ^{th}$ attempt successful})$$ By Bayes' Theorem,

$$P(\text{Drunk|$j ^{th}$ attempt successful}) = \frac{P(\text{Drunk $\cap$ $j ^{th}$ attempt successful})}{P(\text{$j ^{th}$ attempt successful})}$$

Let's find the denominator first. We can do this with the Law of Total Probability $$P(\text{$j ^{th}$ attempt successful}) = P(\text{$j ^{th}$ attempt successful|Drunk})P(\text{Drunk}) + P(\text{$j ^{th}$ attempt successful|Sober})P(\text{Sober})$$

We are told that he comes home drunk about half the time, so $P(\text{Drunk}) = \frac{1}{2}$ and $P(\text{Sober}) = \frac{1}{2}$.

We also know that when drunk he has the chance to repeat keys and when sober he tries the keys without repetition, so $$P(\text{$j ^{th}$ attempt successful|Drunk}) = P(\text{$j$ attempts with repetition}) \\ = \left( \frac{k-1}{k}\right)^{j-1}\frac{1}{k} \\ (\text{Because we get the wrong key $j-1$ times and then the right key}) $$

$$P(\text{$j ^{th}$ attempt successful|Sober}) = P(\text{$j$ attempts without repetition}) = \frac{1}{k}$$

Putting this together:$$P(\text{$j ^{th}$ attempt successful}) = \left( \left( \frac{k-1}{k}\right)^{j-1}\frac{1}{k} \right)\left( \frac{1}{2} \right) + \left( \frac{1}{k} \right) \left( \frac{1}{2} \right) \\ = \left( \frac{1}{2} \right)\left[ \left( \frac{k-1}{k}\right)^{j-1}\frac{1}{k} + \left( \frac{1}{k} \right)\right]$$

Now all that's left is the numerator which we've honestly already done a lot of the work for $$P(\text{Drunk $\cap$ $j ^{th}$ attempt successful}) = P(\text{$j ^{th}$ attempt successful|Drunk})P(\text{Drunk}) \\ \text{(This is the first term in our law of total probability equation)} \\ = \left( \frac{1}{2} \right) \left( \frac{k-1}{k} \right)^{j-1}\frac{1}{k} $$

Altogether now we have:

$$P(\text{Drunk|$j ^{th}$ attempt successful}) = \frac {{\left( \frac{1}{2} \right) \left( \frac{k-1}{k} \right)^{j-1}\frac{1}{k}}}{\left( \frac{1}{2} \right)\left[ \left( \frac{k-1}{k}\right)^{j-1}\frac{1}{k} + \left( \frac{1}{k} \right)\right]} \\ = \frac{\left( \frac{k -1 }{k} \right)^{j-1}}{1 + \left( \frac{k -1 }{k} \right)^{j-1} }$$

If you substitute in the numbers you have, you should end up with $\frac{16}{41} = \overline{.39024}$

  • 977
  • 7
  • 19

Suppose you considered $1000$ instances where the drunk man came to the door. On average, $500$ of them will be when he is drunk, and $500$ when he is sober. If he is sober, then the chance of him taking $3$ tries to open the door is $\frac{1}{5}$ by symmetry. If he is drunk, then the chance is $\frac{4}{5}\cdot\frac{4}{5}\cdot\frac{1}{5}=\frac{16}{125}$. This means that on average there will be $100$ instances of him taking $3$ tries whilst sober, and $64$ whilst drunk. Given that we know he has taken $3$ tries, the probability of him being drunk is therefore $$ \frac{64}{64+100}=\frac{16}{41} \, . $$

  • 14,185
  • 2
  • 28
  • 65