1

having a little trouble with the last part of the knights challenge. When run, it will print nothing for puzzle 3. I have been through the logic countless times now and in my head it seems to work. Any one know why this is not working as expected? Thanks in advance.

knowledge3 = And(
# Information given in the definition of a Knight and Knave puzzle
# Each character is either a knight or a Knave
Or(AKnight, AKnave),
Or(BKnight, BKnave),
Or(CKnight, CKnave),

# Not both
Biconditional(AKnight, Not(AKnave)),
Biconditional(AKnave, Not(AKnight)),

Biconditional(BKnight, Not(BKnave)),
Biconditional(BKnave, Not(BKnight)),

Biconditional(CKnight, Not(CKnave)),
Biconditional(CKnave, Not(CKnight)),

# Information about what the characters actually said
# A says either "I am a knight." or "I am a knave.", but you don't know which.
Or(Implication(AKnight, AKnight), Implication(AKnight, AKnave)),
Or(Implication(AKnave, Not(AKnight)), Implication(AKnave, Not(AKnave))),

# B says "A said 'I am a knave'."
Implication(BKnight, Or(Implication(AKnight, AKnave), Implication(AKnave, Not(AKnave)))),
Implication(BKnave, Or(Not(Implication(AKnight, AKnave)), Not(Implication(AKnave, Not(AKnave))))),

# B says "C is a knave."
Implication(BKnight, CKnave),
Implication(BKnave, CKnight),

# C says "A is a knight."
Implication(CKnight, AKnight),
Implication(CKnave, AKnave)

)

2

How did you reason about this statement:

# Information about what the characters actually said
# A says either "I am a knight." or "I am a knave.", but you don't know which.
Or(Implication(AKnight, AKnight), Implication(AKnight, AKnave)),
Or(Implication(AKnave, Not(AKnight)), Implication(AKnave, Not(AKnave))),

It seems to be a problem with the Or() statement, in the AKnave case. You have two implications, that is:
(A->B) or (A->C) . This could be written as A -> (B or C). If A is AKnight, the statement is correct. If A is AKnave, you want to negate the consequent. That is, A-> Not(B or C). You can use DeMorgans's law to move the Not inside the parenthesis . That is, Not(B or C) becomes Not B AND Not C. That is, A -> (not B AND not C) should be used in the AKNave case. If you want to use two implications, just expand it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .