Information Technology Reference
In-Depth Information
Figure 5.16.
A solution to the second logic problem
logic2.pl
% A second logic puzzle involving jobs and musical instruments
solution(Flute) :-
uniq_people(Doctor,Lawyer,Engineer),
uniq_people(Piano,Violin,Flute),
% Generate values for the three spouse variables.
spouses(Chris_spouse,Sandy_spouse,Pat_spouse),
Chris_spouse = Doctor, % Chris is married to the doctor.
Lawyer = Piano, % The lawyer plays the piano.
\+ Pat_spouse = Engineer, % Pat is not married to the engineer.
Violin = Doctor,
% Sandy is a patient of
\+ sandy = Violin.
% the violinist.
uniq_people(A,B,C) :-
person(A), person(B), person(C), \+ A=B, \+ A=C, \+ B=C.
person(chris). person(sandy). person(pat).
% spouses(X,Y,Z): X,Y,Z can be spouses of Chris,Sandy,Pat.
spouses(none,none,none). % Nobody is married.
spouses(sandy,chris,none). % Chris and Sandy are married.
spouses(pat,none,chris).
% Chris and Pat are married.
spouses(none,pat,sandy).
% Sandy and Pat are married.
constraints that these spouse variables must satisfy derive from the fact that there are
only four marriage possibilities:
Nobody is married.
Chris and Sandy are married.
Chris and Pat are married.
Sandy and Pat are married.
These four possibilities can be handled with four clauses, as shown in figure 5.16.
5.5.2 A more complex logic problem
This
section
considers
an
old
classic
logic
problem,
called
the
zebra
problem,
sometimes attributed to Albert Einstein:
On a street there are five houses of different colors, occupied by five individ-
uals of different nationalities, who own five different pets, drink five different
beverages, and smoke five different brands of (American) cigarettes. Also,
 
Search WWH ::




Custom Search