Great programming question – compliments of Ricky Gervais! | John V. Petersen

:

This is actually an old question, but Ricky Gervais made this one very funny.

In case you have never heard/watched the Ricky Gervais Show on HBO, you should give it a go. Very funny. In the second season, Ricky Gervais and Steve Merchant present Karl Pilkington the following scenario:

Your looking at two doors: one leads to heaven and the other leads to hell. The men guarding the doors and the the doors themselves are identical. They each know who they are. Here’s the one difference: the man guarding hell always lies. The man guarding heaven always tells the truth. You wish to go through the door that leads to heaven and you can ask one question. What question can you ask that will absolutely lead you to the correct door?

The discussion that follows on the pod cast is hilarious. At the end of it, Ricky gives up the correct answer: you ask one of the men which door the other man would say he’s guarding.

For all the humor, they chaps never get into the actual logic behind the puzzle. I’ll get into it here:

– As to truth, we know the two mean are inverses of each other. We know that if we ask each man what door he guards, each man would say heaven (the man guarding heaven would tell the truth and the man guarding hell would lie – saying that he’s guarding heaven). Hence, the ambiguity results. On the other hand, if you ask the one guy what the other would say, you will find the correct door.

If you happen to ask the guy guarding hell what the other guy would say, the guy guarding hell would say hell (because he lies: !(heaven) == hell).

What about the guy guarding heaven? If you ask him what the other guy would say, the guy guarding heaven would say heaven (!(hell) = heaven).

By asking one guy what the other guy would say, you negate the ambiguity the one lie creates. You eliminate the variable. As a result, the answer a guard gives as to what the other guard would say  – is actually the door the guard you are asking is guarding.