# Knights, Knaves, and Spies [closed]

I need help understanding this problem.

An island has three kinds of inhabitants: knights, who always tell the truth, knaves, who always lie, and spies, who can either tell the truth or lie. You encounter three people: A, B, and C, and you know for sure that one is a knight, one is a knave, and one is a spy. Each of the three knows the type of the other two.

• A says, “I am a spy”.
• B says, “I am a spy”.
• C says, “B is a spy”.

What are the types of A, B, and C?

I believe A = knave, B = spy, C = Knight. What do you folks think?

• Well, for a cheap remark: neither $A$ nor $B$ can be the Knight, so....
– lulu
Commented Jul 18 at 0:05
• Yeah, I think I was overthinking it a lot and I believe it wasn't that hard. Thank you Commented Jul 18 at 0:14
• Welcome to PE. Clearly C revealed the truth about A and B .... Where did you spot the puzzle ? Commented Jul 18 at 0:30
• Welcome to Puzzling, take our tour! Could you please provide proper attribution for this question? Commented Jul 18 at 19:11

Your belief that, A = knave, B = spy, C = Knight is correct.

In knight/knave/spy puzzles, it is often best to postpone figuring out who the spy is because a spy can say anything. In other words, a rule of thumb is to begin by trying to figure out who the knight or knave is.

Let’s begin by trying to figure out who the knight is. Both A and B say that they are a spy. Neither of these two can be the knight because then their statements would be lies. So by process of elimination C is the knight. Since C is a knight, C’s statement is true: B is a spy. Finally, by process of elimination A is the knave.

• This logic seems shortest to answer (and could have been written concise but side notes enlarged it). Anyway, shortest, and, in this case, simplest (understandable by many) is a tie break. I propose OP to approve unless better argument. Commented Jul 20 at 2:44

B and C are in agreement, so either both are telling the truth (one is knight and other is spy) or both are lying (one is knave and other is spy).

If B is telling the truth: "I am a spy" true -> B is a spy, so C must be a knight and A is a knave. This means A's statement is false so A is not a spy, which is consistent.

If B is lying: "I am a spy" false -> B is not a spy, so B is a knave. So C must be a spy, and A the knight, so "I am a spy" true -> A is the spy, a contradiction.

The first case holds so A = knave, B = spy, C = knight is correct.

As others have stated, A = knave, B = spy, C = Knight is correct.

Proof using linear programming and Pyomo software within Python.

1. Sets:
• $$I = (1, 2, 3)$$ where (1,2,3) represent the three given constraints
• $$J = (A, B, C)$$ where (A,B,C) represents the three inhabitants
1. Decision Variables:
• $$X_{i} \quad \forall i \in I$$, variables tracking the truth value of each constraint
• $$Y_{j} \quad \forall i \in J$$, variables tracking the the location of our Spy
1. Constraints:

a. A says, “I am a spy”.
b. B says, “I am a spy”.
c. C says, “B is a spy”.

2. Model:

\begin{align} && \text{Minimize:} \quad \text{None} && \\ \text{s.t.} && \\ && X[1] = Y[A] \tag{a}\\ && X[2] = Y[B] \tag{b}\\ && X[3] = 1-Y[B] \tag{c}\\ && X_{i}, Y_{j} \in \{0,1\} && \forall i \in I, \forall j \in J \tag{d} \end{align}

Constraints (a) and (b) equate the X variable to the respective Y variable, meaning that if this statement were true, then that inhabitant would be the spy and both the X and Y values would equal 1, otherwise 0. Constraint (c) equates $$X_{3}$$ to the opposite of the value of $$Y_{B}$$, meaning either the statement is true and $$X_{3} = 0, Y_{B} = 1$$ or the statement is false and $$X_{3} = 1, Y_{B} = 0$$. Constraint (d) ensures that all these variables are binary.

Note: Because we are only searching for a solution that satisfies the given constraints, there exists no true objective function to minimize/maximize.

1. Solution:

$$X_1 = 0, X_2 = 1, X_3 = 0$$, indicating that statement 2 (B says, "I am a spy'") and statement 3 (C says, "B is a spy") are true.

$$Y_A = 0, Y_B = 1, Y_C = \text{None}$$, agreeing with our X variables above.

$$Y_A$$ = 0 so A is our Knave, $$Y_B$$ = 1 so B is our Spy, leaving $$Y_C$$ as our Knight (ignore the 'None' value for $$Y_C$$).

• Welcome to PSE (Puzzling Stack Exchange)! Commented Jul 18 at 18:03