-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle3.py
64 lines (54 loc) · 1.58 KB
/
puzzle3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from logic import *
# Puzzle 2
# A says "We are the same kind." Lie => Knave
# B says "We are of different kinds." Truth => Knight
# A is a knave
# B is a knight
AKnight = Symbol("A is a Knight")
AKnave = Symbol("A is a Knave")
BKnight = Symbol("B is a Knight")
BKnave = Symbol("B is a Knave")
# KB initial rules
InitialKnowledge = And(
Or(AKnight, AKnave),
Or(BKnight, BKnave),
Not(And(AKnight, AKnave)),
Not(And(BKnight, BKnave)),
)
# Initial Statment given by A
InitalStatement_SameKind = And(
# If Aknight <=> Bknight
Biconditional(AKnight, BKnight),
# If Aknight <=> Not(Aknave)
Biconditional(AKnight, Not(AKnave)),
# If Aknight <=> Not(BKnave)
Biconditional(AKnight, Not(BKnave))
)
# Initial Statment given by B
InitalStatement_DifferentKind = And(
# If Aknight <=> Bknave
Biconditional(AKnight, BKnave),
# If BKnight <=> Aknave
Biconditional(BKnight, AKnave),
# If Aknight <=> Not(BKnight)
Biconditional(AKnight, Not(BKnight)),
# If AKnave <=> Not(Bknave)
Biconditional(AKnave, Not(BKnave)),
)
knowledge = And(
InitialKnowledge,
# If A is a knight their initial statment must be true
Biconditional(AKnight, InitalStatement_SameKind),
# If B is a knight their initial statment must be true
Biconditional(BKnight, InitalStatement_DifferentKind),
)
def main():
symbols = [AKnight, AKnave, BKnight, BKnave]
if len(knowledge.conjuncts) == 0:
print("Not yet implemented.")
else:
for symbol in symbols:
if model_check(knowledge, symbol):
print(f" {symbol}")
if __name__ == "__main__":
main()