Top Banner
Logic Puzzles - Knights and Knaves AE1APS Algorithmic Problem Solving John Drake
20

AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

Mar 31, 2015

Download

Documents

Jaheim Burnley
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

Logic Puzzles - Knights and Knaves

AE1APS Algorithmic Problem SolvingJohn Drake

Page 2: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

The island of Knights and Knaves is a fictional island to test peoples’ ability to reason logically.

There are two types of people on the island. Knights who always tell the truth Knaves who always lie.

The island of Knights and Knaves.

Page 3: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

Knaves?

Page 4: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

Logic puzzles are about deducing facts about the island, from statements made by the people on the island. But you do not know whether the statement was made by a knight or a knave.

The island of Knights and Knaves.

Page 5: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

What happens if you ask a person if they are a knight or a knave?

There may be gold on the island. What question could you ask to establish this?

Some examples

I’m a Knight

I’m a Knight

Page 6: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

At school we learnt to manipulate expressions. The values of expressions are numbers

n2 –m2 = (n + m)(n - m) To do this we use laws. e.g. n + 0 = n and n – n = 0 (for ANY values of

n) Associatively of addition (m + n) +p = m + (n + p) I am sure you are all familiar with laws

regarding addition, multiplication.

Algebra

Page 7: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

Boolean expressions are either true or false. Boolean valued expressions are called

propositions. “it is sunny” is an atomic Boolean

expression. “it is sunny and warm” is non atomic as it

can be broken down into two expressions. We are concerned with the rules for

manipulating Boolean expressions.

Boolean algebra

Page 8: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

Equality is a binary relation. It is a function with a range of Boolean values

true and false. Equality is reflexive: [x ≡ x] It is symmetric: [x ≡ y is the same as y ≡ x] It is transitive: [x ≡ y and y ≡ z implies z ≡ x] If x ≡ y, then f(x) ≡ f(y) It is associative: [(x ≡ y) ≡ z is the same as

x ≡ (y ≡ z) ] It is substitutive [x ≡ (y ≡ z) can be replaced

by (y ≡ z) ≡ (y ≡ z) ]

Boolean Equality.

Page 9: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

“A” is a native on the island. Therefore A is either a knight or a knave. The statement “A is a knight” is either true or

false. The statement “there is gold on the island” is

either true or false. Suppose “A is a knight”, and suppose A makes

statement S. The crucial observation is that the values of

these two propositions are the same. Then “A is a knight” ≡ S

Knights and knaves.

Page 10: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

Suppose A is the proposition “person A is a knight" and suppose A makes a statement S. We can infer that A is true is the same as S is true. That is,

A≡S

More formally…

Page 11: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

If A says “I am a knight” then all we can infer from the statement is A ≡ A. Not much use!

Similarly, it cannot be that a native says “I am a knave” because we would then conclude

A ≡ ¬A which is always false.

If A says “I am the same type as B". We infer that A ≡ (A ≡ B) which simplifies to B.

Examples

¬ Boolean symbol for negation (i.e. NOT A)

Page 12: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

A native says “there is gold on this island, is the same as, I am a knight”.

Let G denote the proposition “There is gold on the island". A's statement is A ≡ G. So what we are given is:

A ≡ A ≡ G This simplifies to G. So we deduce that there

is gold on the island but it is not possible to tell whether A is a knight or a knave.

Going for gold

Page 13: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

If A is a knight, he will always tell the truth so we will know there is gold on the island.

If A is a knave he will always lie so when asked if A ≡ G (i.e. Are the answers to “Are you a knight?” and “Is there gold on the island?” the same), he will answer true when there is gold on the island and false if not.

If not clear will go through case analysis using truth tables

In natural language

Page 14: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

Given a pair of natives, what question would you ask to discover if the other one is a knight?

Another example to think about…

Page 15: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

A tourist comes to a fork in a road, one way leads to a restaurant, the other does not. What question (yes/no) would you ask a native to find out which way it is to the restaurant?

Getting directions

Page 16: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

Let Q be the question to be posed.

The response to the question will be A ≡ Q

Let L denote, “the gold can be found by following the left fork”

The requirement is that L is the same as the response to Q. i.e. we require L ≡ (A ≡ Q)

What question to ask?

Page 17: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

{but as equality is associative} (L ≡ A) ≡ Q So the question Q posed is L ≡ A i.e. “is the value of ‘the restaurant can be

found by following the right fork’ equal to the value of ‘you are a knight’”

What question to ask?

Page 18: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

There are three natives A, B and C.

C says “A and B are both the same type”

Formulate a question, that when posed to A determines if C is telling the truth.

Equals for Equals

Page 19: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

Let A be the statement “A is a knight”. Let Q be the unknown question. The response we want is C

(i.e. if C is true then C is a knight). By the previous example, Q ≡ (A ≡ C) i.e. we

replace L by C. C’s statement is A ≡ B, so now we know

C ≡ (A ≡ B) by equality. So Q ≡ (A ≡ (A ≡ B)) which simplifies to Q ≡ B,

Therefore the question to be posed is “is B a knight?”

Equals for equals

Page 20: AE1APS Algorithmic Problem Solving John Drake. The island of Knights and Knaves is a fictional island to test peoples ability to reason logically. There.

Never trust a knave

Equality is reflexive, symmetric, transitive, substitutive and associative – know these!

More knights and knaves on Thursday

Coursework 1, 2 and 3 now online, deadline for Coursework 3 is Thursday 15th November at 1pm

http://www.cs.nott.ac.uk/~jqd/AE1APS-1213/ [email protected] http://en.wikipedia.org/wiki/Knights_and_Knaves

Key points