% There's two doors, one is unsafe.
safe(a) :- true.
safe(b) :- false.

% There's two agents, one of them lies. (you can't tell who's the liar).
askX(Preposition) :- \+ Preposition.
askY(Preposition) :- Preposition.
?- askX(askY(safe(a))). % X, if I ask Y if A is the safe door, how would you respond?
false.
?- askX(askY(safe(b))). % X, if I ask Y if B is the safe door, how would you respond?
true.
?- askY(askX(safe(a))). % Y, if I ask X if A is the safe door, how would you respond?
false.
?- askY(askX(safe(b))). % Y, if I ask X if B is the safe door, how would you respond?
true.

Unfortunately SWI-Prolog doesn't support pattern matching with the \+ predicate...

Feb 6, 2023, 1:33 PM
0 0 0

comments