rendered paste body%
% FAMILY CIRCLE
%
% Logic Problems Issue 10 page 10
%
% The Spredditt family sat down to tea at their circular table.
% From the clues given below, can you discover who sat in which position,
% how old each is and what spread each chose to use on his or her bread?
%
% Clues:
% 1. The 12-year old sat between Pam and the peanut-butter fanatic,
% who sat directly facing his father.
%
% 2. The boy who likes raspberry jam sat diametrically opposite the person
% who prefers marmalade.
%
% 3. Sam is not 14, though one of his neighbors at the table is 44.
%
% 4. Gill, who is 16, was sitting next to her mother, who likes honey
% and whose seat number on the plan is three less than that of
% the shrimp-paste fancier.
%
% 5. Father sat in seat 1.
%
% Family: Father, Mother, Bill, Gill, Pam, Sam
% Ages: 12, 14, 16, 18, 43, 44
% Spreads: Blackcurrant jam, honey, marmalade, peanut butter,
% raspberry jam, shrimp paste
%
% Person:_______________
% Age: _______________
% Spread:_______________
% 1
%
% _____________ _______________
% _____________ 6 2 _______________
% _____________ _______________
%
%
% _____________ _______________
% _____________ 5 _______________
% _____________ 3 _______________
%
% 4
% _______________
% _______________
% _______________
%
%
facing(1,4).
facing(2,6).
facing(3,5).
facing(4,1).
facing(6,2).
facing(5,3).
male(bill).
male(sam).
male(father).
female(mother).
female(gill).
female(pam).
solve(C) :-
C = [[1,_,_,_], [2,_,_,_], [3,_,_,_], [4,_,_,_], [5,_,_,_], [6,_,_,_]],
% 1. The 12-year old sat between Pam and the peanut-butter fanatic,
% who sat directly facing his father.
E1 = [_,NAME1,12,_],
male(NAME1),
E2 = [N1,pam,_,_],
E3 = [N2,_,_,peanut_butter],
E4 = [N3,father,_,_],
facing(N2,N3),
member(E1,C),
member(E2,C),
member(E3,C),
member(E4,C),
adjacent(E1,E2,C),
adjacent(E1,E3,C),
opposite(E3,E4,C),
\+ N1 == N2,
% 2. The boy who likes raspberry jam sat diametrically opposite the person
% who prefers marmalade.
E5 = [_,RJ_NAME,_,raspberry_jam],
E6 = [_,_,_,marmalade],
male(RJ_NAME),
member(E5,C),
member(E6,C),
opposite(E5,E6,C),
% 3. Sam is not 14, though one of his neighbors at the table is 44.
E7 = [N4,sam,_,_],
E8 = [N5,_,14,_],
E9 = [N6,_,44,_],
member(E7, C),
member(E8, C),
member(E9, C),
\+ N4 == N5,
\+ N4 == N6,
adjacent(E7,E9,C),
% 4. Gill, who is 16, was sitting next to her mother, who likes honey
% and whose seat number on the plan is three less than that of
% the shrimp-paste fancier.
E10 = [_,gill,16,_],
E11 = [HONEY_NUM,mother,_,honey],
E12 = [SHRIMP_NUM,_,_,shrimp_paste],
member(E10, C),
member(E11, C),
member(E12, C),
adjacent(E10,E11,C),
HONEY_NUM is SHRIMP_NUM - 3,
% 5. Father sat in seat 1.
E13 = [1,father,_,_],
member(E13, C),
member([_,bill,_,_],C),
member([_,_,_,blackcurrent_jam], C),
member([_,_,18,_],C),
member([_,_,43,_],C),
% 6. (Implicit) Father/Mother ages must be higher than the children's ages.
member([_,father,FATHER_AGE,_],C),
member([_,mother,MOTHER_AGE,_],C),
member([_,_,PEANUT_AGE,peanut_butter],C),
member([_,gill,GILL_AGE,_],C),
FATHER_AGE > 18,
MOTHER_AGE > 18.
adj(X, Y, [X, Y|_]).
adj(X, Y, [Y, X|_]).
adj(X, Y, [_|Z]) :- adj(X, Y, Z).
adjacent(X,Y,L) :-
append(L,L,L2),
adj(X,Y,L2).
opp(X, Y, [X, _, _, Y|_]).
opp(X, Y, [Y, _, _, X|_]).
opp(X, Y, [_|Z]) :- opp(X, Y, Z).
opposite(X,Y,L) :-
append(L,L,L2),
opp(X,Y,L2).
C = [[1, father, 44, blackcurrent_jam], [2, sam, 18, marmalade], [3, mother, 43, honey], [4, gill, 16, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 44, blackcurrent_jam], [2, sam, 18, marmalade], [3, mother, 43, honey], [4, gill, 16, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 44, blackcurrent_jam], [2, sam, 18, marmalade], [3, mother, 43, honey], [4, gill, 16, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 44, blackcurrent_jam], [2, sam, 18, marmalade], [3, mother, 43, honey], [4, gill, 16, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 43, blackcurrent_jam], [2, sam, 18, marmalade], [3, mother, 44, honey], [4, gill, 16, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 43, blackcurrent_jam], [2, sam, 18, marmalade], [3, mother, 44, honey], [4, gill, 16, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 43, blackcurrent_jam], [2, sam, 18, marmalade], [3, mother, 44, honey], [4, gill, 16, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 43, blackcurrent_jam], [2, sam, 18, marmalade], [3, mother, 44, honey], [4, gill, 16, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 43, blackcurrent_jam], [2, gill, 16, marmalade], [3, mother, 44, honey], [4, sam, 18, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 43, blackcurrent_jam], [2, gill, 16, marmalade], [3, mother, 44, honey], [4, sam, 18, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 43, blackcurrent_jam], [2, gill, 16, marmalade], [3, mother, 44, honey], [4, sam, 18, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 43, blackcurrent_jam], [2, gill, 16, marmalade], [3, mother, 44, honey], [4, sam, 18, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 44, blackcurrent_jam], [2, sam, 18, marmalade], [3, mother, 43, honey], [4, gill, 16, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]] ;
C = [[1, father, 44, blackcurrent_jam], [2, sam, 18, marmalade], [3, mother, 43, honey], [4, gill, 16, peanut_butter], [5, bill, 12, raspberry_jam], [6, pam, 14|...]]