All pastes #235660 Raw Edit

Someone

public text v1 · immutable
·published 2006-11-03 11:24 UTC
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).

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 = [_,_,12,_],
	E2 = [_,pam,_,_],
	E3 = [N1,_,_,peanut_butter],
	E4 = [N2,father,_,_],
	(facing(N1,N2) ; facing(N2,N1)),

	member(E1,C),
	member(E2,C),
	member(E3,C),
	member(E4,C),

	adjacent(E1,E2,C),
	adjacent(E1,E3,C),
	opposite(E3,E4,C),
	\+ E2 == E3,


% 2. The boy who likes raspberry jam sat diametrically opposite the person
%    who prefers marmalade.

	E5 = [_,_,_,raspberry_jam],
	E6 = [_,_,_,marmalade],
	
	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 = [_,sam,_,_],
	E8 = [_,_,14,_],
	E9 = [_,_,44,_],

	member(E7, C),
	member(E8, C),
	member(E9, C),
	\+ E7 == E8,

	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),
	E13 == E4,

	member([_,bill,_,_],C),

	member([_,_,_,blackcurrent_jam], C),

	member([_,_,18,_],C),	
	member([_,_,43,_],C).

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).


%%% SAMPLE OUTPUT %%%

[33] 43 ?- solve(C).

C = [[1, father, 14, blackcurrent_jam], [2, pam, 18, raspberry_jam], [3, mother, 12, honey], [4, gill, 16, peanut_butter], [5, sam, 43, marmalade], [6, bill, 44|...]] ;

C = [[1, father, 14, blackcurrent_jam], [2, pam, 43, raspberry_jam], [3, mother, 12, honey], [4, gill, 16, peanut_butter], [5, sam, 18, marmalade], [6, bill, 44|...]] ;

C = [[1, father, 14, blackcurrent_jam], [2, pam, 18, raspberry_jam], [3, mother, 12, honey], [4, gill, 16, peanut_butter], [5, sam, 43, marmalade], [6, bill, 44|...]] ;

C = [[1, father, 14, blackcurrent_jam], [2, pam, 43, raspberry_jam], [3, mother, 12, honey], [4, gill, 16, peanut_butter], [5, sam, 18, marmalade], [6, bill, 44|...]] ;

C = [[1, father, 14, blackcurrent_jam], [2, pam, 18, raspberry_jam], [3, mother, 12, honey], [4, gill, 16, peanut_butter], [5, sam, 43, marmalade], [6, bill, 44|...]] ;

C = [[1, father, 14, blackcurrent_jam], [2, pam, 43, raspberry_jam], [3, mother, 12, honey], [4, gill, 16, peanut_butter], [5, sam, 18, marmalade], [6, bill, 44|...]] ;

C = [[1, father, 14, blackcurrent_jam], [2, pam, 18, raspberry_jam], [3, mother, 12, honey], [4, gill, 16, peanut_butter], [5, sam, 43, marmalade], [6, bill, 44|...]] ;

C = [[1, father, 14, blackcurrent_jam], [2, pam, 43, raspberry_jam], [3, mother, 12, honey], [4, gill, 16, peanut_butter], [5, sam, 18, marmalade], [6, bill, 44|...]] ;

C = [[1, father, 18, blackcurrent_jam], [2, pam, 14, raspberry_jam], [3, mother, 12, honey], [4, gill, 16, peanut_butter], [5, sam, 43, marmalade], [6, bill, 44|...]] ;

C = [[1, father, 43, blackcurrent_jam], [2, pam, 14, raspberry_jam], [3, mother, 12, honey], [4, gill, 16, peanut_butter], [5, sam, 18, marmalade], [6, bill, 44|...]] ;

C = [[1, father, 18, blackcurrent_jam], [2, pam, 14, raspberry_jam], [3, mother, 12, honey], [4, gill, 16, peanut_butter], [5, sam, 43, marmalade], [6, bill, 44|...]] 

.
.
.
etc
etc
.
.
.