-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzle2.py
41 lines (32 loc) · 980 Bytes
/
puzzle2.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
from logic import *
# Puzzle
# A says "We are both knaves." => A is a Knave
# B says nothing => B is a Knight (Because Knaves always lie part of what they said must be a lie)
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)),
)
# Statement given to us
InitialStatment = And(AKnave, BKnave)
knowledge = And(
InitialKnowledge,
# If A is a Knight his initial statment will be true
Biconditional(AKnight, InitialStatment)
)
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()