Arlene(A), Brenda(B), Cheryl(C), Daniel(D), Emmett(E) and Farley(F) stayed in a hotel.
1) Each stayed in a different one of six rooms as shown here, identified by his initials :
+----+----+----+----+
| | C | | E |
| B +----+ D +----+
| | | | |
+----+ +----+ +
| A | F |
+---------+---------+
2) One of the six murdered one of the other five.
3) If the murderer and the victim stayed in rooms that did not border on each other, then Arlene or Farley was the victim.
4) If the murderer and the victim stayed in rooms that bordered on different numbers of rooms, then Brenda or Cheryl was the murderer.
5) If the murderer and the victim stayed in rooms that were different in size, then Daniel or Emmett was the murderer.
Who was the murderer? Who was the victim?
Program solution in the Prolog languagePreparationTransposition of the information given by the drawing
into an adjacency matrix:
A B C D E F Number Size
of Bord.
--------------------------------------------------------
A 0 1 1 1 0 1 4 big
B 1 0 1 0 0 0 2 med
C 1 1 0 1 0 0 3 sma
D 1 0 1 0 1 1 4 med
E 0 0 0 1 0 1 2 sma
F 1 0 0 1 1 0 3 big
------------------------------------------------------
P r o g r a m
------------------------------------------------------
:- op(1050, xfy, =>). % Def.log.Operator '=>' for Conditional
P => Q :- + P, !. % (P -> Q) <=> (~P v Q)
P => Q :- Q.
b(a,4,3). % 1st Arg = Person/Room
b(b,2,2). % 2nd Arg = Number of Bordering Rooms
b(c,3,1). % 3rd Arg = Size: big=3, med=2, sma=1
b(d,4,2).
b(e,2,1).
b(f,3,3).
e(a,b). % e(X,Y) = Edge between X and Y,
e(a,c). % if '1' in matrix
e(a,d).
e(a,f).
e(b,a).
e(b,c).
e(c,a).
e(c,b).
e(c,d).
e(d,a).
e(d,c).
e(d,e).
e(d,f).
e(e,d).
e(e,f).
e(f,a).
e(f,d).
e(f,e).
solution(murd(M1),vict(V1)) :-
b(M1,Bm,Sm),b(V1,Bv,Sv),
dif(M1,V1),
(+ (M1=b ; M1=c) => (Bm=:=Bv) ), % Contrapos. of 4)
(+ (M1=d ; M1=e) => (Sm=:=Sv) ), % Contrapos. of 5)
(+ (V1=a ; V1=f) => ( e(M1,V1) ). % Contrapos. of 3)
-----------------------------------------
Q u e r y
-----------------------------------------
?- solution(M,V).
M = murd(d),
V = vict(a).
Edited on June 29, 2017, 3:40 pm
|
Posted by ollie
on 2017-04-11 15:16:33 |