Knights and Knaves is a type of logic puzzle devised by Raymond Smullyan.
On a fictional island, all inhabitants are either knights, who always tell the truth, or knaves, who always lie. The puzzles involve a visitor to the island who meets small groups of inhabitants. Usually the aim is for the visitor to deduce the inhabitants' type from their statements, but some puzzles of this type ask for other facts to be deduced. The puzzle may also be to determine a yes/no question which the visitor can ask in order to discover what he needs to know.
An early example of this type of puzzle involves three inhabitants referred to as A, B and C. The visitor asks A what type he is, but does not hear A's answer. B then says "A said that he is a knave" and C says "Don't believe B: he is lying!" To solve the puzzle, note that no inhabitant can say that he is a knave. Therefore B's statement must be untrue, so he is a knave, making C's statement true, so he is a knight. Since A's answer invariably would be "I'm a knight", it is not possible to determine whether A is a knight or knave from the information provided.
In some variations, inhabitants may also be alternators, who alternate between lying and telling the truth, or normals, who can say whatever they want (as in the case of Knight/Knave/Spy puzzles). A further complication is that the inhabitants may answer yes/no questions in their own language, and the visitor knows that "bal" and "da" mean "yes" and "no" but does not know which is which. These types of puzzles were a major inspiration for what has become known as "the hardest logic puzzle ever".
Some Examples of "Knights and Knaves" puzzles
A large class of elementary logical puzzles can be solved using the laws of Boolean algebra and logic truth tables. Familiarity with boolean algebra and its simplification process will help with understanding the following examples.
John and Bill are residents of the island of knights and knaves.
Question 1
John says: We are both knaves.
Who is what?
Question 2
John: If (and only if) Bill is a knave, then I am a knave.
Bill: We are of different kinds.
Who is who?
Question 3
Here is a rendition of perhaps the most famous of this type of puzzle:
John and Bill are standing at a fork in the road. You know that one of them is a knight and the other a knave, but you don't know which. You also know that one road leads to Death, and the other leads to Freedom. By asking one yes/no question, can you determine the road to Freedom?
This version of the puzzle was further popularised by a scene in the 1986 fantasy film, Labyrinth, in which Sarah (Jennifer Connelly) finds herself faced with two doors each guarded by a two-headed knight. One door leads to the castle at the centre of the labyrinth, and one to certain doom. It had also appeared some ten years previously, in a very similar form, in the Doctor Who story Pyramids of Mars.
Solution to Question 1
John is a knave and Bill is a knight.
John's statement is: "Both John and Bill are knaves."
If John were a knight, he would not be able to say that he was a knave since he would be lying. John being a knave makes the statement "Both John and Bill are knaves." false. Hence either John is a knight or Bill is a knight. Since John can't be a knight, Bill must be a knight for the statement to hold.
Solution for Question 2
John is a knave and Bill is a knight.
In this scenario, John is saying the equivalent of "we are not of different kinds" (that is, either they are both knights, or they are both knaves). Bill is contradicting him, saying "we are of different kinds". Since they are making contradictory statements, one must be a knight and one must be a knave. Since that is exactly what Bill said, Bill must be the knight, and John is the knave.
Solution to Question 3
There are several ways to find out which way leads to freedom. One alternative is asking the following question: "Will the other man tell me that your path leads to freedom?"
If the man says "No", then the path does lead to freedom, if he says "Yes", then it does not. The following logic is used to solve the problem.
If the question is asked of the knight and the knight's path leads to freedom, he will say "No", truthfully answering that the knave would lie and say "No". If the knight's path does not lead to freedom he will say "Yes", since the knave would say that the path leads to freedom.
If the question is asked of the knave and the knave's path leads to freedom he will say "no" since the knight would say "yes" it does lead to freedom. If the Knave's path does not lead to freedom he would say Yes since the Knight would tell you "No" it doesn't lead to freedom.
The reasoning behind this is that, whichever guardian the questioner asks, one would not know whether the guardian was telling the truth or not. Therefore one must create a situation where they receive both the truth and a lie applied one to the other. Therefore if they ask the Knight, they will receive the truth about a lie; if they ask the Knave then they will receive a lie about the truth.
Note that the above solution requires that each of them know that the other is a knight/knave. An alternate solution is to ask of either man, "What would your answer be if I asked you if your path leads to freedom?"
If the man says "Yes", then the path leads to freedom, if he says "No", then it does not. The reason is fairly easy to understand, and is as follows:
If you ask the knight if their path leads to freedom, they will answer truthfully, with "yes" if it does, and "no" if it does not. They will also answer this question truthfully, again stating correctly if the path led to freedom or not.
If you ask the knave if their path leads to freedom, they will answer falsely about their answer, with "no" if it does, and "yes" if it does not. However, when asked this question, they will lie about what their false answer would be, in a sense, lying about their lie. They would answer correctly, with their first lie canceling out the second.
This question forces the knight to say a truth about a truth, and the knave to say a lie about a lie, resulting, in either case, with the truth.
Another alternative is to ask: "if, and only if, you agree with me in that you are both different, could you point me to Freedom?" The logic behind this being that the knave will be unable to answer since he cannot agree that both are different because he would be telling the truth. Therefore the knight would point you in the right direction.
Another alternative is to ask: "Is either one of the following statements correct? You are a Knight and at the same time this is the path to freedom; or you are a knave and this is not the path to freedom". More alternatives for a question to ask can be found using Boolean algebra.