# XKCD inspired logic puzzle

I came up with a logic puzzle inspired by this xkcd comic. I don't yet have an answer, and I am wondering if anyone can come up with one.

You are in a room with three doors. Two of the doors lead out, but one of them leads to certain death. Each door has a guard holding a spear stationed in front of it. One of the guards always lies, one always tells the truth, and the third guard will fatally stab you if you ask a tricky question. If the question isn't tricky, he will tell the truth.

For this puzzle, "tricky question" is a question that is:

• A "meta-question" about the guards.

Example: "If I asked Guard X about topic Y, what would he say?"

Example: "If I asked you about Topic Y, what would you reply if you were a liar?"

Another example: "If there were N doors, and I asked you question X, what would you respond?"

• Will he fatally stab me? – Will Sep 23 '16 at 22:49
• What does the third guard do if you ask him a non-tricky question? – gtwebb Sep 23 '16 at 22:54
• What about shooting the guard before you get stabbed? – Oriol Sep 23 '16 at 23:04
• Without some definition of what a "tricky question" consists of, I don't think an accurate one-question answer can be determined. – Siyual Sep 24 '16 at 0:16
• You don't state a limit on the number of questions which can be asked, nor if there are any other limitations on what can be asked (other than not "tricky"). This effectively results in an infinite number of accurate answers. – Makyen Sep 24 '16 at 6:11

With two questions, you can ask for the first question:

What planet are we on?

Based on the answer you'll know if they speak the truth or lies.

If they're lying:

Since two speak the truth, and only one lies, just pick any other guard and ask them which door leads to safety.

If the they're telling the truth:

• Perhaps you might want to generalize it to any true, non-tricky questions for the first question. You may not know the planet you are on ;) – Conor O'Brien Sep 24 '16 at 3:31
• Replace the planet question by asking a guard whether they are a guard. That's a known fact in the puzzle. – user5971 Sep 24 '16 at 10:49
• Or ask "Am I myself?" If they say yes, then you have the truth teller. If they say no, then you have the false teller. And, of course, if you find yourself gasping for breath with a sharp pain in your side, it's probably a good time to think about whether self-referential statement qualifies as "tricky," even if the answer is pretty obvious to most people. – Cort Ammon Sep 24 '16 at 16:47
• @RenéG One of the guards always lies Always – Destructible Lemon Sep 25 '16 at 9:26
• @ReneG a)wrong, and b) if right, this puzzle has no solution cause the lying guard could ALWAYS behave like a truth telling guard until he betrays you, so you just cannot win. – Patrice Sep 25 '16 at 13:49

Now that "Tricky" has been defined, I can easily do this in one question which, while tricky, does not violate any of the constraints.

Question:

Asked to Guard 1: Is exactly one of the statements "you always lie" and "the door you guard leads to certain death" true?

This has four possible cases: Liar + Death, Liar + Safe, Truthteller + Death, Truthteller + Safe. A quick check of the logic shows:

Liar + Death = Guard says Yes
Liar + Safe = Guard says No
Truthteller + Death = Guard says Yes
Truthteller + Safe = Guard says No

Thus, if the Guard says No, pick their door. If they say Yes, pick one of the other doors.

• I dont think the first question would be tricky. It asks if someone is a liar. I would think a question is tricky if its more like "if i asked gaurd 2 if he was a liar would he say yes" because you are then basically running the question through 2 gaurds. – gtwebb Sep 24 '16 at 0:09
• @gtwebb we are getting back to the fundamental definition of what makes a question "tricky", and the reality is that the OP provided no such definition and one is not clear from context. This means that solutions are inherently subjective. – Robert Columbia Sep 24 '16 at 1:06
• Edited based on definition of "Tricky". – Zerris Sep 24 '16 at 3:44
• I would definitely argue that this question is very meta, considering that you specifically want the guard to reveal his status as a liar. – pipe Sep 24 '16 at 7:19
• Doesn't matter, I don't think - the individual statements aren't questions, just features of the world. It's like asking "is either 3 or 5 less than 4?" - a liar has to say "No", because there's only one thing to lie about. – Zerris Sep 25 '16 at 3:07

Two questions and no trickery:

Ask the 2nd guard "Does the 1st guard's door lead to certain death?"

Take these actions depending on their answers:

1. Yes and yes, they are both telling the truth, use a different door.
2. Yes and no, one of them is telling the truth, use a different door.
3. No and yes, one of them is telling the truth, use a different door.
4. No and no, both are telling the truth, use that door.

• simplest answer :) – Wasiq Shahrukh Oct 6 '16 at 4:17
• -1, uses a "meta-question" about the first guard. – Buffer Over Read Oct 15 '16 at 17:02
• How is it a meta question? I'm asking the guard a single question, not a question about a question. – jstnthms Oct 23 '16 at 3:24

A lot depends on your definition of tricky, as has been commented. It could be that any question that gets you out is tricky, making it unsolvable.

Would you like me to buy you all a beer?

Then regardless of how they answer, you can just follow them out to the nearest pub and buy them a beer.

The question does not specifically disallow this yet, so you could:

Ask in a loud voice and a general manner: "Does this door lead out"? If you get two "Yes" and one "No" then go out through it. If not, then go out through one of the other ones.

My strategy:

Ask the first guard three questions:
"Does the first door lead out?"
"Does the second door lead out?"
"Does the third door lead out?"
Either all answers will be the truth, or all answers will be lies. Since two doors lead out, and one leads to death, I just have to take one of the two doors for which he gives the same answer.

• You only need to ask 2 questions about the 1st and 2nd doors. If the answers are the same, either door leads out. If the answers are different, you know the 3rd door leads out. – Paul Evans Sep 25 '16 at 15:42
• @PaulEvans: Good point. – celtschk Sep 25 '16 at 19:12

As long as the floodgates have opened, and people are submitting responses with three questions:

Pick a door.
Two of the answers you get will be the truth, so, if you get "Yes", "Yes" and "No" (in any order), the door leads out, so you can use it, and if you get "Yes", "No" and "No", the door leads to death, and you should use one of the others.

Trivial optimization: if the first two guards give the same answer, you know that's the truth, and you don't need to ask the third guard.

• Your optimization isn't necessarily right, what if the liar is guarding the door to death? He would say yes too. – dcfyj Oct 13 '16 at 15:32
• @dcfyj: I don’t understand your comment. You’re right, up to a point.  If I pick the door that leads to death, and I ask “Does this door lead out?”, the liar will say “Yes”.  But the other two guards will say “No”. If I happen, by random choice/good luck, to ask the two honest guards first, I’ll get two “No” answers, and the optimization works.  If I happen, by random choice/bad luck, to ask the liar first or second, then my first two answers will be one of each (“Yes” and “No”), then the optimization does not apply, and I am forced to ask the third guard (who is guaranteed to tell the truth). – Peregrine Rook Oct 13 '16 at 17:22
• Ok, I misread what you said. I thought you were saying that you were asking each guard about his own door. Rather than asking each guard about a specific door. – dcfyj Oct 13 '16 at 17:29
• @dcfyj: That answer wouldn’t work at all if the liar was guarding the death door.  If I asked each guard, “Does your door lead out?”, they would all say “Yes”, and I’d learn nothing useful.  Only if an honest guard was guarding the death door would I get two negative answers and one affirmative, and I would go through the door whose guard said “Yes” (because he would be an honest guard in front of an exit door). … (Cont’d) – Peregrine Rook Oct 13 '16 at 17:50
• (Cont’d) …  And I can optimize that: if the first two guards that I asked said “No”, I would know that the third door was the exit.  And if the first two guards gave one of each answer, I would know that the one who said “Yes” was guarding an exit.  … … … … … … … … … … … … … … … … … … … … … … … … … …  My point is that, if my answer had been what you thought it was, then the whole answer would have been flawed, and not just the optimization. – Peregrine Rook Oct 13 '16 at 17:51

Had a quick stab at this, could probably work it out a bit more...

Anyway, I started using statistics mixed with logic to try and maximise the chance of living.

One Question, nothing tricky:

Ask any guard- Is this door safe?

This won't give a definite answer, but can increase the chances of your survival (if you are lucky). Here's my reasoning behind it:

Since we're using a simple question, there's a 2/3 chance that the guard will tell the truth.
If we were to pick any random door, there's a 2/3 chance that we are safe anyway.

Using these two facts, we can try to scrape together some stats to increase our chance of survival:

I'll use the abbreviations T for 'Truth-teller', L for 'Liar', S for 'Safe' and D for 'Death', Yes for 'Yes' and N for 'No'

• 2/3 T AND 2/3 S = 4/9 Y S
• 2/3 T AND 1/3 D = 2/9 N D
• 1/3 F AND 2/3 S = 2/9 N S
• 1/3 F AND 1/3 D = 1/9 Y D

With these results, we can further group things by the answer given.

If answer is Yes- 4/9 Chance of Safety, 1/9 Chance of Death
This becomes 80% Chance of Safety, 20% chance of Death.

If answer is No- 2/9 Chance of Safety, 2/9 Chance of Death
Which works out as 50/50.

So, given all this info, you could make a decision:

If they Answer 'No', Pick any door, it's a 2/3 chance of survival.
If they Answer 'Yes', Pick this door, it's a 80% chance of survival.

Like I said, this was just a quick stab, Maybe someone else could stack the odds a bit better with a different question?

I'm operating under the assumption that we're only allowed one question. I also believe my one question does not fall under the two current "tricky" guidelines. It's definitely not a hypothetical, and I don't think it counts as "meta", since it's very straightforward. But you be the judge.

For ease, assume the doors are numbered 1, 2, 3 and the guards are similarly numbered. Rephrasing the question to get the same result is easy if they're not. The question is...

Ask guard 1 : Is exactly one of the statements "Guard 1 is the liar" and "Door 1 is safe" true?

If you get the response "yes":

If Guard 1 tells the truth, then exactly one of the two statements is true. Clearly the first is not true, so Door 1 must be safe. If Guard 1 lies, then the first statement is true. So in order for the guard to lie, both statements must be true and Door 1 is safe. Conclusion: Door 1 is safe.

If you get the response "no":

A truth telling Guard 1 answering "no" means either both statements are true or both are false. The first is clearly not true. Therefore the second must also be false and Door 1 is not safe. If Guard 1 is lying, that means exactly one of the two statements is true and it must be the first, so the second is false and Door 1 is not safe. Either way, Door 1 is not safe - pick a different one.

I'm curious if this would fall under the "meta" category the OP described. To me, it's a straightforward question about the truth values of two statements.

• The same question can be formulated as: "Are you the truthteller or stabber and guarding the door to certain death, or the liar and not guarding the said door?". – Florian F Dec 1 '19 at 0:10

Since I don't yet have enough reputation to comment, I'm asking this in an answer.

How many questions are we allowed to ask the guards?

The other answers that have been suggested have varying numbers of questions suggested, and the task becomes fairly trivial if there's no limit to the number of questions askable. In order to prevent the puzzle from being too open-ended, I think that a maximum number of questions should be specified.

Are you the guard that stabs?

With that information:

You know that the one who answers "No" tells the truth.

And so, finally:

Ask the truthful guard for directions on the way out.

Explanation:

The stabby guard will answer "Yes" because he tells the truth. The liar will know the answer is "No", but will lie and answer "Yes". Only the truth-teller will answer "No".

But I bet that the whole labyrinth is just a trap to capture escaping logicians.

Question Stats: Two on a best-case scenario, four on a worst case scenario.

Actually, i have a simper definition of tricky question, which is almost certainly the intended one. A "tricky question" is one that both the lying guard and the truth telling guard would answer identically, and would tell you which door to go through. With two questions allowed, the solution is trivial if you can ask the same guard two questions. you can ask one non tricky question to determine if the guard you are speaking to is telling the truth (Are my eyes open?), and ask a second question of a guard that tells the truth. (is this door safe). With three allowed, you can ask the same non tricky question of all three, and two will agree. If only two questions are allowed, and they may not be asked of the same guard, then we have a problem, as while it's easy to identify a guard as a truth teller or not, you can't act on that knowledge. Here's my not tricky question.
"Which doors are safe?" The truth teller and the stabby guard will point to the two safe doors. the lying guard must point to the opposite of what the truth telling guards would, which is ONE dangerous door. So either two doors will be pointed at, which are safe, or one door will be pointed at, which will kill you. This only works because there are three doors. If there were two, this wouldn't work.

Assuming the doors are numbered 1, 2, and 3, ask the guard in front of door #2, "Is the sum of the number on the liar's door and the number on the door that leads to death, even". If the answer is "yes", proceed through door #2. Otherwise, pick #1 or #3 arbitrarily (both will be safe).

If the liar is #2, the liar will falsely answer "NO" when door in the middle is dangerous (the sum will be 2+2), and falsely answer "YES" when it isn't (the sum will be 2+1 or 2+3, which are both odd).

If the liar is #1 or #3, the #2 guardian will truthfully answer "YES" when the door in the middle is safe (the sum could be 1,1 1+3 3+1, or 3.3, i.e. 2, 4, 4, or 6) and truthfully answer "NO" when it is dangerous (the sum will be 1+2 or 3+2, i.e. 3 or 5).

No need for meta-questions or hypotheticals. The door in front of the liar has some number, and the dangerous door has some number, and adding them together would yield some number which will be either even or odd.

The title text states

And the whole setup is actually a trap to capture escaping logicians. None of the doors actually lead out.

Given the scenario in the comic, you die regardless. However, if one of the doors did actually lead to freedom, I would use the Monty Hall problem to my advantage using the following steps...

2. Announce your choice to the guards.
3. Ask one of the guards "Is your spear pointy?" If the guard says no, you know that he is the liar.
4. Instruct one of the truth-telling guards to open a door that leads to death.
5. Go through the door you originally chose. There is a 2/3 chance you will live.
• If you've established who are the truth-telling guards, why not just ask them to point you to a safe door? – Arkku Sep 24 '16 at 12:44
• Since there's only one door leading to death, as soon as he opened it, it doesn't matter which of the other doors you use. – celtschk Sep 24 '16 at 13:02
• And BTW, if a 2/3 chance is enough for you, you can just randomly choose one of the doors and ignore the guards altogether. ;-) – celtschk Sep 24 '16 at 13:19
• I assumed only one door led to life. I was also trying to get away with asking only one question. – Caleb Reister Sep 24 '16 at 15:45
• Go through the door you originally chose. There is a 2/3 chance you will live. - there was already a 2/3 chance that you chose a safe door. 2-4 have no real bearing on anything. I don't think the Monty Hall problem is really applicable here. – Ant P Oct 6 '16 at 12:23

If the "stabby" guard answers randomly,

Then you're better off just taking a random door and skipping the questions. Asking questions results in a 50% of being directed to the wrong door (and probably a greater chance of being stabbed), just going through doors gives you a 67% chance of surviving.

If the "stabby" guard is just silent:

Ask an easy question (is 1+1 2?). If he's silent then just pick a door and skip the 2nd question. If he answers then you'll know if he's the liar and can use your 2nd to find the door.

Edit: A truthful tricky guard is handled just like if you'd talked to the truthful guard to start with.

• Mr. Stab will tell the truth, if it's not a tricky question. (Definition of tricky is in the original question) – margalo Sep 24 '16 at 2:49
• Please edit this into the original question for clarity. – Shawn V. Wilson Sep 24 '16 at 3:08
• Also, there's some disagreement whether the question "Is Guard 2 the guard that always lies?" a tricky question or not. – Shawn V. Wilson Sep 24 '16 at 3:17

Pick 1 door. For each guard, ask: "Is that door leading out?"

if it is: Mr.Truth & Mr.Stab: "Yes" Mr.Lie: "No". if it is not: Mr.Truth & Mr.Stab: "No", Mr.Lie: "Yes".

if you get 2 yes, go out that door. else, go out any other door.

I have an answer in 2 questions that works 100% of the time if only ONE door leads to safety.

Question 1:

Ask one guard: Are you the truth-teller guard? If he says yes, stay with him. If he says no, find one of the other guards.

Explanation:

The truth-teller and liar would say yes, but the stabber would say no. We want to avoid the stabber so we can ask a tricky question.

Question 2:

If I asked you, “Is it the case that the truthful answer to this question would be no and that door (point to a door not behind him) leads to safety, or your door leads to safety?”, would you say yes? If he doesn’t answer, go through the door you pointed to. If he says yes, take his door. If he says no, take the third door.

Explanation:

The or statement must be an inclusive or (maybe it can be worded better). This question becomes a paradox if the door you pointed to leads to safety due to the and statement. The or statement makes the answer yes if his door leads to safety, and the and statement makes the answer no if the third door leads to safety (left as an exercise to the reader).

• Welcomed to Puzzling SE! Please take the tour – North Læraðr Feb 22 '19 at 14:52