Skip to content

Instantly share code, notes, and snippets.

@davidventuri
Last active November 14, 2023 13:44
Show Gist options
  • Save davidventuri/4bb876dc8812c1a9d188237548fa70a7 to your computer and use it in GitHub Desktop.
Save davidventuri/4bb876dc8812c1a9d188237548fa70a7 to your computer and use it in GitHub Desktop.
Logic puzzles. Knights must tell the truth. Knaves always lie.

Knights & Knaves

You are shipwrecked on an unknown island where there are two kinds of people - knights & knaves. Knights always tell the truth and knaves always lie. To survive, you need to know who is who.

For each person in the following scenarios, can you figure out if they are a knight or a knave? Support your answer with a logical justification / proof.

1. Persons: A & B

  • A says: “B is a knave.”
  • B says: “We are both knights.”

Case 1: A = knight, B = knight. If A is a knight, then B must be a knave. Contradiction.

Case 2: A = knight, B = knave. If A is a knight, then B must be a knave. If B is a knave, then they are not both knights. No contradiction.

Case 3: A = knave, B = knight. If B is a knight, then they are both knights. Contradiction.

Case 4: A = knave, B = knave. If A is a knave, then B must be a knight. Contradiction.

Verdict: A is a knight and B is a knave.

2. Persons: A & B

  • A says: “We are both knights."
  • B says: “We are both knaves.”

Case 1: A = knight, B = knight. If B is a knight, then both must be knaves. Contradiction.

Case 2: A = knight, B = knave. If A is a knight, then both must be knights. Contradiction.

Case 3: A = knave, B = knight. If B is a knight, then they are both knaves. Contradiction.

Case 4: A = knave, B = knave. If B is a knave, then both are not knaves. Contradiction.

Verdict: Someone is breaking the rules!

3. Persons: A, B & C

  • A says: “B is a knave.”
  • B says: “C is a knave.”
  • C says: “B and myself are knights.”

Case 1: A = knight, B = knight, C = knight. If A is a knight, B is a knave. Contradiction.

Case 2: A = knight, B = knight, C = knave. If A is a knight, B is a knave. Contradiction.

Case 3: A = knight, B = knave, C = knight. If C is a knight, B and C are knights. Contradiction.

Case 4: A = knight, B = knave, C = knave. If B is a knave, C is a knight. Contradiction.

Case 5: A = knave, B = knight, C = knight. If B is a knight, C is a knave. Contradiction.

Case 6: A = knave, B = knight, C = knave. If A is a knave, B is a knight. If B is a knight, C is a knave. If C is a knave, B and C are not knights (but one could be). No contradiction.

Case 7: A = knave, B = knave, C = knight. If A is a knave, B is a knight. Contradiction.

Case 8: A = knave, B = knave, C = knave. If A is a knave, B is a knight. Contradiction.

Verdict: A is a knave, B is a knight, and C is a knave.

4. Persons: A & B

  • A says: “At least one of the two of us is a knight.”
  • B says: “La la la!”

Case 1: A = knight, B = knight. If A is a knight, then knights >= 1. No contradiction.

Case 2: A = knight, B = knave. If A is a knight, then knights >= 1. No contradiction.

Case 3: A = knave, B = knight. If A is a knave, then knights < 1. Contradiction.

Case 4: A = knave, B = knave. If A is a knave, then knights < 1. No contradiction.

Three possible scenarios exist:

  • Both A and B are knights
  • A is a knight and B is a knave
  • Both A and B are knaves
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment