freeCodeCamp/guide/english/logic/knights-and-knaves/index.md

1.9 KiB
Raw Blame History

title
Knights and Knaves Puzzles

Knights and Knaves

One type of logic puzzle, these puzzles have to do with two types of people. Knights: people who only tell the truth and Knaves: people who only tell lies. Raymond Smullyan collected dozens of puzzles like this in his book, "What is the Name of This Book?". The way the puzzles work is that a person visits an island where he meets an inhabitant or group. The visitor must use his logic skills to figure out who is the knight and who is the knave.

Sample Puzzles

Red and Blue

Two people, Red and Blue, stand before you. Red says, “We are both knaves.” What are they really?

Solution: Red cannot be a knight, because then he would be lying by saying he is a knave. Therefore he is a knave, and his statement is a lie, meaning that Blue must be a knight.

Which Path to Take?

You come to a fork in a road and need to learn which path leads to your destination. Two individuals are standing there. You know that one is a knight and one is a knave, but you dont know which is which. What single yes-or-no question could you ask of one of the islanders to learn the correct path?

Solution: Point to a path and ask of one, “Would the other one tell me that this is the correct path?” If the answer is No, that is the correct path; if Yes, it is the incorrect path.

More Information: