Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!linus!decvax!harpo!seismo!hao!hplabs!sri-unix!Warren@SRI-AI
From: Warren@SRI-AI@sri-unix.UUCP
Newsgroups: net.lang.prolog
Subject: Puzzle Solution
Message-ID: <3589@sri-arpa.UUCP>
Date: Wed, 27-Jul-83 17:37:02 EDT
Article-I.D.: sri-arpa.3589
Posted: Wed Jul 27 17:37:02 1983
Date-Received: Mon, 1-Aug-83 08:21:45 EDT
Lines: 45

From:  David Warren 

Here's a solution to the puzzle Russ Abbott posed.

% Liars and Non-Liars Puzzle

% On a certain island the inhabitants are partitioned into those who
% always tell the truth and those who always lie.  I landed on the
% island and met three inhabitants A, B, and C.  I asked A, "Are you a
% truth-teller or a liar?"  He mumbled something which I couldn't make
% out.  I asked B what A had said.  B replied, "A said he was a liar."
% C then volunteered, "Don't believe B, he's lying."  What can you tell
% about A, B, and C?

:-op(900,xfx,if).
:-op(800,xfy,and).
:-op(700,xfx,[is_in,isnt_in]).
:-op(100,fy,not).

says(a,mumble).
says(b,says(a,liar(a))).
says(c,liar(b)).

liar(X) if says(X,Y) and not Y.
not liar(X) if says(X,Y) and Y.
not says(X,Y) if not liar(X) and not Y.
not says(X,Y) if liar(X) and Y.

provable(P and Q,A) :- !, provable(P,A), provable(Q,A).
provable(P,_) :- P.
provable(P,A) :- P is_in A.
provable(P,A) :- P isnt_in A, P if Q, negation(P,P1), provable(Q,[P1|A]).

P is_in [P|_].
P is_in [_|A] :- P is_in A.

P isnt_in [].
P isnt_in [P1|A] :- P \== P1, P isnt_in A.

negation(not P,P) :- !.
negation(P, not P).

:- provable(liar(X),[]), write(X), write(' is a liar.'), nl.

:- provable(not liar(X),[]), write(X), write(' is not a liar.'), nl.