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

30 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
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.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
#### More Information:
* <a href='https://www.amazon.com/gp/product/0486481980/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0486481980&linkCode=as2&tag=brenconl05-20&linkId=UU6GFKPWEKZFK2XG' target='_blank' rel='nofollow'>What is the Name of This Book? from Amazon</a>
* <a href='https://en.wikipedia.org/wiki/Knights_and_Knaves' target='_blank' rel='nofollow'>Wikipedia Article</a>