# Two doors, two guards, and two keys

• The puzzle - read the puzzle itself.

• Warming up - read about solutions to a simpler variation of the puzzle.

Introduction

(Edit: Improved the wording and clarified the "Introduction" section.)

Before stating the puzzle, I want to introduce the idea behind it.

This puzzle is an extension to the well known classic guards and doors puzzle.

In short, there we only need to figure out which doors are which. But, it is actually possible to additionally deduce which guard is which as well. This extension is motivated by the fact that none of the answers given in the linked classic accomplish this additional task.

You may notice that this extension is not possible to solve if we can only distinguish yes or no answers from a single yes or no question (one bit of information is not sufficient).

Note that a single yes or no question can actually receive four distinct answers, making this puzzle solvable. The other two answers are represented by a paradox (the guard can't answer) and by tautology (the guard can answer either yes or no).

The goal of this puzzle is to find a question that expects a yes or no answer, such that depending on whether it was: answered with a yes, answered with a no, couldn't be answered, or was simultaneously answered with a yes and a no; You can deduce the information about both the guards and the doors.

The puzzle

You find yourself in a cryptic room with two guards, each guarding a door and carrying a key.

One guard is a truth teller (T), and the other one is a liar (L). You can't tell which one is which. Similarly, the doors are indistinguishable from each other. You know that one of the two doors leads to Freedom (F), and the other to damnation (D).

The truth teller holds the key to the freedom door, and the liar holds the key to the damnation door. The only way to freedom is to both pick the correct door and the correct key (guard).

The only thing you are allowed to do before picking a door and a key, is to ask a single yes or no question to one of the guards.

If the guard is given a choice to answer either truthfully or untruthfully, they will follow their inclination and answer with either a decisive YES or a decisive NO. That is, the truth teller will never lie, and the liar will always lie.

If the truth teller cannot answer truthfully, or if a liar cannot answer untruthfully, then they will remain MUTE. However, if they can satisfy their inclination with either yes or no answer, they will produce an arcane SCREECH representing a simultaneous yes and no answer.

What do you ask the guard to deduce both his inclination and the door he is guarding?

There are four scenarios to consider, and four answers we can receive.

We can be asking T who guards F, T who guards D, L who guards F, or L who guards D.

The answer will either be a YES, a NO, a SCREECH, or a MUTE response.

The solution to the puzzle needs to be a question representing a bijection between these scenarios and answers. We know of at least one solution, with variations to it being possible.

Warming up

From now on, we will be discussing answers to the classic guards and doors puzzle.

The following part of this post spoils the linked puzzle, and possibly gives hints to solving this puzzle. You have been warned.

For the first example, the following questions (answers) solve the linked puzzle using YES, NO answers. That is, we can deduce which doors are which by asking:

1.a

Ask "Is the truth telling guard standing in front of the door that leads to freedom?"

1.b

Both 1.a and 1.b will result in the following answers: (to TF, LF, TD, LD scenarios):

T L
F Yes Yes
D No No

This tells us which doors are which, but does not tell you which guard is the liar and which one is the truth teller (it does not give you the key).

2.a

2.b

Ask "Among the propositions 1. 'You are a liar', 2. 'You will reply negatively' and 3. 'This door leads to freedom', is there an odd number of true propositions?"

Both 2.a and 2.b will result in the following answers: (to TF, LF, TD, LD scenarios):

T L
F Screech Screech
D Mute Mute

This again only tells us which door is which, not revealing anything about the keys (the inclination of the guards).

The problem of this post is, to pose a question such that "YES", "NO", "SCREECH" and "MUTE" answers all appear exactly once in the answer table.

For example, the solution I found gives the following answer table:

$$\begin{array}{c|cc} & T & L \\ \hline F & \text{No} & \text{Yes} \\ D & \text{Screech} & \text{Mute} \end{array}$$

Based on this, we can now ask the guard such a question, and then respond as:

• If we hear No, we take the key from the asked guard and enter his door.
• If we hear Yes, we take the key from the other guard and enter the door of the asked guard.
• If we hear a Screech, we take the key from the asked guard, and enter the other door.
• If they remain Mute, we take the key from the other guard and enter the other guards door.

To always unlock the freedom door with the truth tellers key.

Can you find such solution (question)?

Is it the case that the door behind you leads to freedom and your answer to this question is "yes"?

YES: I take B's key and open B's door.
NO: I take A's key and open B's door.
SCREECH: I take A's key and open A's door.
SILENCE: I take B's key and open A's door.

Why:

Call the statement "A's door leads to freedom" $$S_1$$. Call the statement "A's answer is 'yes'" $$S_2$$. So the question asked is whether the conjunction $$S_3 = (S_1 \land S_2)$$ is true.

If A tells the truth and guards the door to freedom ($$S_1$$ true), he could answer either "Yes", making $$S_2$$ true and $$S_3$$ true, or "No", making $$S_2$$ false and $$S_3$$ false. So the result is a SCREECH.

If A lies and guards the door to freedom ($$S_1$$ true), he cannot answer "Yes", making $$S_2$$ true and $$S_3$$ true, or "No", making $$S_2$$ false and $$S_3$$ false. So the result is SILENCE.

If A guards the door to damnation ($$S_1$$ false), then $$S_3$$ must be false no matter what the truth value of $$S_2$$. So if A tells the truth he must answer NO. If A lies he must answer YES.

• This is the closest thing to the solution that we think is simplest and clearest, congrats! Nov 26, 2019 at 7:00
• Although, am I missing something or should YES and NO be swapped in the last explanation? Nov 26, 2019 at 7:07
• Oops, you're right. Fixed, I think. Nov 26, 2019 at 14:54
• We decided to accept your answer as we believe it is as simple as it can get. We also decided to provide our solution as a self contained answer for completion. :) Nov 26, 2019 at 16:05

Here's a question which I think works.

I've secretly tossed a coin. If I asked the truthteller "Is it true that my coin showed heads or the left door leads to freedom?", would they give the same answer as you are giving to this question?

Explanation:

Suppose the left door leads to freedom. Then the truthteller would say "yes" in answer to your hypothetical question. If the guard you asked the actual question to is the truthteller, they could say either "yes" (the same as "yes") or "no" (not the same as "yes") truthfully. So they will screech. On the other hand, if you asked the liar, they could not say either "yes" or "no" untruthfully, so they will stay mute.
Now suppose the left door does not lead to freedom. The truthteller won't know the answer to your hypothetical question, so would remain silent. Thus if you are speaking to the truthteller they will truthfully say "no" (not the same as mute), whereas if you are speaking to the liar they will untruthfully say "yes" (not the same as mute).

(Note: I came up with this without reading the extra "warming up" section, so my question doesn't produce the exact same table that you had, but can be easily modified to do so.)

• If I'm not missing anything, this question does work as a solution. I liked your idea of using a "hypothetical random statement (such as a coin toss)" to work in all four answers, good job! ( Response to your note: The "warming up" section is optional and acts as a hint, you do not need to use anything from there so all is fine.) $-$ The intended solution does not need to use a "hypothetical random statement", so who ever is reading trough this, feel free to try to find such solution. Nov 25, 2019 at 11:50

I originally missed the piece saying that the truthteller holds the key to freedom, so I solved the harder puzzle where that information is not known. I still like this, though.

If I wrote down the truthful answer to whether the truthteller's key opens the door to freedom, then your answer to this question, then the truthful answer to whether the truthteller's door leads to freedom, would I write a "yes" before a "no"?

Yes: I take guard A's key and open guard B's door.
No: I take guard B's key and open guard A's door.
Silence: I take guard A's key and open guard A's door.
Screech: I take guard B's key and open guard B's door.

Full explanation:

Case 1: The first and third answers are both "Yes": The truthteller has the key to freedom and stands in front of the door to freedom. If guard A tells the truth, he cannot answer Yes making sequence YYY and cannot answer N making sequence YNY, so he remains silent. So I take A's key and use A's door; since A is the truthteller, I'm free. If guard A lies, he can answer Yes making sequence YYY or can answer No making sequence YNY, so he screeches. So I take B's key and use B's door; since B is the truthteller, I'm free.

Case 2: The first answer is "Yes" and the third answer is "No": The truthteller has the key to freedom and the liar stands in front of the door to freedom. No matter whether the sequence is YYN or YNN, the truthful answer is "Yes". If guard A tells the truth, he must answer "Yes". So I take A's key and open B's door; since A is the truthteller and B the liar, I'm free. If guard A lies, he must answer "No". So I take B's key and open A's door; since B is the truthteller and A the liar, I'm free.

Case 3: The first answer is "No" and the third answer is "Yes": The liar has the key to freedom and the truthteller stands in front of the door to freedom. No matter whether the sequence is NYY or NNY, the truthful answer is "No". If guard A tells the truth, he must answer "No". So I take B's key and open A's door; since B is the liar and A is the truthteller, I'm free. If guard A lies, he must answer "Yes". So I take A's key and open B's door; since A is the liar and B the truthteller, I'm free.

Case 4: The first and third answers are both "No": The liar has the key to freedom and stands in front of the door to freedom. If guard A tells the truth, he can answer "Yes" making sequence NYN or "No" making sequence NNN, so he screeches. So I take B's key and open B's door; since B is the liar, I'm free. If guard A lies, he cannot answer "Yes" making sequence NYN or "No" making sequence NNN, so he is silent. So I take A's key and open A's door; since A is the liar, I'm free.

That is, a question is needed such that sometimes the guard cannot answer, and other times he can answer with both a yes or a no (it does not matter).

So the question is about time. Meaning sometime you ask the question they may not be able to answer, while other times they can. This means you can ask the same question multiple times.

1. 'It's morning and you are a liar', 2. 'you will answer negatively' and 3. 'This door leads to freedom', is there an odd number of true propositions?"

First ask this question in the morning. If you get an answer, you are pointing at the freedom door. If you are pointing at the death door, it will be silence. so you will know which door is the door to freedom.

Now let's ask the same question in the afternoon. Pointing at the freedom door and ask the same question. The guard is a truthteller, if he or she answers yes or no. If you don't get any answer, the guard is a liar because answer yes or no would cause paradox

• That is a nice out of the box idea. But, the expected solution would ask a single question once. The "sometimes answerable" was intended to refer to one of the four situations that are possible when asking the question (TF, LF, TD, LD). I thought this was clarified with the answer tables. Nevertheless, I liked your interpretation even though this was not intended. Nov 25, 2019 at 7:10
• I want to add on for any future readers, that technically the cited "Remark" section used in this answer to justify it was not a part of "The puzzle", and was now edited to hopefully make that clear. Nov 25, 2019 at 9:19

Here is the question I came up with when trying to mix 1b and 2a from above:

If we let the truth-telling guard be T, and the current guard being asked the question C, then if I were to ask you, ""if we let this question being asked be Q, would T’s response to the question “Is C guarding the freedom door?” be equivalent to T’s response to the question “Is Q true and does C have the key?”?"", what would you say? (Let the most outer/first quote level be "", second level be ", and third level be ') General expression after noting that the inner if statement makes truth-telling guards and lying guards respond like the truth-telling guard would to Q: Q = (G = (P and K)). This isn't a pretty question, but it does the job.

Let's break this question up a little more.

First, we have the outer if statement to make both the liar and truth-telling guards both speak the truth of Q. So, it would be the same as asking the truth-telling guard the following question: If we let the truth-telling guard be T, the current guard being asked the question C, and this question being asked be Q, would T’s response to the question “Is C guarding the freedom door?” be equivalent to T’s response to the question “Is Q true and does C have the key?”?

I took a different approach and tried to phrase my question in such a way that it doesn't matter if I am asking the truth-telling guard or the lying guard.

First, let us look at the case in which the person being asked is the truth-telling guard who happens to be guarding the freedom door and have the key to the freedom door:

Then, we have two things to attempt: The answer to the question is yes, and the answer to the question is no. I will show both of these in great detail and revert to the expression for the rest.

1) First, let us look at the assumption that the answer to the question is yes. Then, the subquestion of T's response to “Is C guarding the freedom door?” would be yes. The subquestion of T's response to “Is Q true and does C have the key?” would be yes since the former is assumed to be true and the latter is true. Are the first and subquestions equivalent? YES! Is this equivalent to the assumption? YES!

2) Next, let us look at the assumption that the answer to the question is no. Then, the subquestion of T's response to “Is C guarding the freedom door?” would be yes. The subquestion of T's response to “Is Q true and does C have the key?” would be no since the former is assumed to be false and the latter is true, making the overall subquestion false. Are the first and subquestions equivalent? NO! Is this equivalent to the assumption? YES!

This makes this combination SCREECH because both answers can result in the question being "YES"

All right, now I will go through the other examples fairly rapidly. For the rest of these situations for the guard being asked, I will use T/L to indicate this guard is the truth-telling or lying guard one, F/D to indicate that the guard is guarding the freedom door or death door, and H/N to indicate that the guard has the key to the freedom door or not.

The previous example tested was then TFH.

Going onwards:

TFN:

1. T = (T = (T and F)) -> T = (T = F) -> T = F -> F, 2. F = (T = (F and F)) -> F = (T = F) -> F = F -> T, NO

TDH:

1. T = (F = (T and T)) -> F, 2. F = (F = (F and T)) -> F, MUTE

TDN:

1. T = (F = (T and F)) -> T, 2. F = (F = (F and F)) -> F, YES

The F guards have the exact same statement results as the above four.

This makes the chart as follows:

$$\begin{array}{c|cc}\\ & F & D \\ \hline \\ H & \text{Screech} & \text{Mute} \\ \\ N & \text{No} & \text{Yes} \\ \end{array}$$

So, if C screeches, take C's key and go through C's door. If C says no, take the other guard's key and go through C's door. If C stays mute, take C's key and go through the other guard's door. Finally, if C says yes, take the other guard's key and go through the other guard's door.

There are quite a few other similar variations of this question that can be asked. Here is some code I made that generates some of these said variations:

https://gist.github.com/bob312123/3d5d79bf976d0d10ebf8d96d931bece3

• Although unnecessarily complex, your question appears to work. I'm not sure why you also handled the key cases (H/N) when it is stated in the puzzle that the truth teller holds the freedom key, and that the liar holds the damnation key. Nevertheless, I see you put in some effort +1. Nov 25, 2019 at 17:10
• @Vepir I completely missed that somehow. Ah, well. It was fun anyways. Nov 25, 2019 at 17:37
• Oh, so the reason your answer is much more complex than the expected solution, is that it seems your question accomplishes more than asked (works even if keys get shuffled). You have that the T/L tables consisting of F/D + H/N cases are the same and individually have four distinct answers. That's nice. Nov 25, 2019 at 18:06
• Oh, I also missed that the truthteller always holds the freedom key. Which means mine could get simpler also. Nov 26, 2019 at 0:23

I don't have a complete answer, but I feel like this way of looking at it makes some progress:

Their answer consists of two different bits of information: whether they can answer 'yes' consistently with their truth inclination, and whether they can answer 'no'. If they can only answer one, that's the answer they give. If both are possible, they screech. If neither is consistent, they are silent.

Now we just need to frame a question that whether they can say yes or not tells us something about where the key is, and whether they can say no or not tells us which door to take.

This is where I'm stuck. I haven't yet been able to construct a question that is sometimes answerable and sometimes unanswerable. I'll edit if I make any progress framing a question that could get 4 distinct answers.

Is exactly one of the following statements true? 1) You are honest. 2) Your answer to this question is true and you guard the Freedom door.

This answer will explain in detail how we arrived at our initial simple solution.

The question that you can ask the guard is:

"Would your answers to 'Is liar guarding Freedom?' and this question both be 'yes'?

The explanation of why it works:

We can analyse the four scenarios, and examine what would T/L guard say to the 'Is liar guarding Freedom?' subquestion, and what would happend if he also said yes or no to the question itself. $$\begin{array}{} \text{Scenario} & \text{Is L gurding F?} & \text{Yes} & \text{No} & \text{Final Answer} \\ \text{T guards F} & \text{No (Truth)} & \text{(Lie)} & \text{(Truth)} & \text{No} \\ \text{L guards F} & \text{No (Lie)} & \text{(Lie)} & \text{(Truth)} & \text{Yes} \\ \text{T guards D} & \text{Yes (Truth)} & \text{(Truth)} & \text{(Truth)} &\text{Screech} \\ \text{L guards D} & \text{Yes (Lie)} & \text{(Truth)} & \text{(Truth)} & \text{Mute} \\\end{array}$$ All four final answers are distinct, hence we always know which guard is the truth teller (who holds the freedom key), and which door leads to freedom.

To arrive at the given answer (question that solves the puzzle), we made the following observation:

Notice that answering the question "$$Q:$$ is $$(Q = Q_1 = Q_2)$$ true?" with yes/no if $$Q_1, Q_2$$ are the same (yes,yes or no,no) either forces a truth or a lie (a screech or a mute answer). When $$Q_1,Q_2$$ are distinct, then $$Q$$ allows either a lie or truth to be told.

Hence, we can choose $$Q_2$$ as either a constant 'Yes' or 'No', and choose $$Q_1$$ in the simplest way to encode a guard and a door, such as 'Is Liar guarding Freedom?'. We are done.