[bp-users]Puzzle to solve in prolog
Kenn
kenn@d2.net.au
Mon, 7 Oct 2002 10:02:10 +1000
This is a multi-part message in MIME format.
------=_NextPart_000_0005_01C26DE8.9A2FA850
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hey guys,
Can anyone help me in solving this puzzle in prolog code? I'm having =
problems.
% S I G N I N G O N
% ___________________
%
% Logic Problems Issue 16 page 46
%
%On one page of the visitor's book at Sandholme Castle, seat of the Duke =
of
%Wallingfen, were the names of ten couples from various locations in the
%English-speaking world who had paid to look round the ancestral pile.
%From the clues given below, can you fill in the blank page of the book =
with
%the surnames and home-towns of each couple?
%
%Clues:
%1. The Drummonds are from Edinburgh; their name appears on the line =
above the
% Jones family, who were not the last couple to sign the page.=20
%2. Mr and Mrs Ince's signatures are immediately followed by those of =
the London couple.
%3. The couple on line 3 gave a North American address; their surname =
contains
% two more letters than that of the Portsmouth pair and three more =
than that
% of the couple on line 9.
%4. Only one couple's surname initial immediately preceeds that of the =
next
% family to sign; they are not the Childers family, whose name appears =
on line 5
% and who do not live in Melbourne.
%5. Bristol is the address on the line above Durban; one of these cities =
is the
% home of the Adams family.
%6. The Los Angeles couple signed on line 8; their surname contains an =
even
% number of letters.
%7. Mr and Mrs Fellowes, who are not transatlantic visitors, wrote their =
name on
% an odd-numbered line, unlike the couple from Wellington.
%8. The Toronto family's name immediately follows that of the =
Harringtons, who
% are not from Washington.
%9. Mr and Mrs Bourne signed on the lower half of the page, whilst the =
Giles
% family, who did not sign on line 6, are not resident in the U.K.
%
%London, Edinburgh, Bristol and Portsmouth are all in the U.K. Durban is =
in
%South Africa. Los Angeles and Washington (D.C.) are in the U.S.A. =
Toronto is in
%Canada. Wellington is in NewZealand. And of course, Melbourne is in =
Australia.
letters(adams,5).
letters(bourne,6).
letters(childers,8).
letters(drummond,8).
letters(edwards,7).
letters(fellowes,8).
letters(giles,5).
letters(harrington,10).
letters(ince,4).
letters(jones,5).
precedes(adams,bourne).
precedes(bourne,childers).
precedes(childers,drummond).
precedes(drummond,edwards).
precedes(edwards,fellowes).
precedes(fellowes,giles).
precedes(giles,harrington).
precedes(harrington,ince).
precedes(ince,jones).
% Hint: the following predicate may be needed as part of clue 4.
% however, it should be used after all the clues are coded.
% check_preceds counts the number of couples whose surnames precedes
% that of the next couple
check_precedes([_], 0) :- !.
check_precedes([[_,N1,_], [_,N2,_]| T], N) :-
precedes(N1, N2), !,
check_precedes([[_,N2,_]|T], M),
N is M + 1.
check_precedes([_, [_,N2,_]|T], N) :-
check_precedes([[_,N2,_]|T], N).
This is the solution to check your answer with.
L =3D [[1, drummond, edinburgh], [2, jones, portsmouth], [3, edwards, =
washington], [4, giles, wellington], [5, childers, bristol], [6, adams, =
durban], [7, fellowes, melbourne], [8, harrington, los_angeles], [9, =
ince, toronto], [10, bourne, london]]
Hope you guys can help.
Thanks.
Regards.
Ken.
------=_NextPart_000_0005_01C26DE8.9A2FA850
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hey guys,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Can anyone help me in solving this =
puzzle in prolog=20
code? I'm having problems.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial>% S I G N I N G O=20
N<BR>% ___________________<BR>%<BR>% Logic Problems Issue 16 page=20
46<BR>%<BR>%On one page of the visitor's book at Sandholme Castle, seat =
of the=20
Duke of<BR>%Wallingfen, were the names of ten couples from various =
locations in=20
the<BR>%English-speaking world who had paid to look round the ancestral=20
pile.<BR>%From the clues given below, can you fill in the blank page of =
the book=20
with<BR>%the surnames and home-towns of each =
couple?<BR>%<BR>%Clues:<BR>%1. The=20
Drummonds are from Edinburgh; their name appears on the line above=20
the<BR>% Jones family, who were not the last couple to sign =
the=20
page. <BR>%2. Mr and Mrs Ince's signatures are immediately followed by =
those of=20
the London couple.<BR>%3. The couple on line 3 gave a North American =
address;=20
their surname contains<BR>% two more letters than that of =
the=20
Portsmouth pair and three more than that<BR>% of the couple =
on line=20
9.<BR>%4. Only one couple's surname initial immediately preceeds that of =
the=20
next<BR>% family to sign; they are not the Childers family, whose =
name=20
appears on line 5<BR>% and who do not live in =
Melbourne.<BR>%5.=20
Bristol is the address on the line above Durban; one of these cities is=20
the<BR>% home of the Adams family.<BR>%6. The Los Angeles =
couple=20
signed on line 8; their surname contains an even<BR>% number =
of=20
letters.<BR>%7. Mr and Mrs Fellowes, who are not transatlantic visitors, =
wrote=20
their name on<BR>% an odd-numbered line, unlike the couple =
from=20
Wellington.<BR>%8. The Toronto family's name immediately follows that of =
the=20
Harringtons, who<BR>% are not from Washington.<BR>%9. Mr and =
Mrs=20
Bourne signed on the lower half of the page, whilst the =
Giles<BR>% =20
family, who did not sign on line 6, are not resident in the=20
U.K.<BR>%<BR>%London, Edinburgh, Bristol and Portsmouth are all in the =
U.K.=20
Durban is in<BR>%South Africa. Los Angeles and Washington (D.C.) are in =
the=20
U.S.A. Toronto is in<BR>%Canada. Wellington is in NewZealand. And of =
course,=20
Melbourne is in=20
Australia.<BR><BR><BR>letters(adams,5).<BR>letters(bourne,6).<BR>letters(=
childers,8).<BR>letters(drummond,8).<BR>letters(edwards,7).<BR>letters(fe=
llowes,8).<BR>letters(giles,5).<BR>letters(harrington,10).<BR>letters(inc=
e,4).<BR>letters(jones,5).<BR><BR>precedes(adams,bourne).<BR>precedes(bou=
rne,childers).<BR>precedes(childers,drummond).<BR>precedes(drummond,edwar=
ds).<BR>precedes(edwards,fellowes).<BR>precedes(fellowes,giles).<BR>prece=
des(giles,harrington).<BR>precedes(harrington,ince).<BR>precedes(ince,jon=
es).<BR><BR>%=20
Hint: the following predicate may be needed as part of clue 4.<BR>% =
however, it=20
should be used after all the clues are coded.<BR>% check_preceds counts =
the=20
number of couples whose surnames precedes<BR>% that of the next=20
couple<BR><BR>check_precedes([_], 0) :- !.<BR>check_precedes([[_,N1,_],=20
[_,N2,_]| T], N) :-<BR> precedes(N1, N2),=20
!,<BR> check_precedes([[_,N2,_]|T], =
M),<BR> =20
N is M + 1.<BR>check_precedes([_, [_,N2,_]|T], N) =
:-<BR> =20
check_precedes([[_,N2,_]|T], N).<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>This is the solution to check your =
answer=20
with.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV>L =3D [[1, drummond, edinburgh], [2, jones, portsmouth], [3, =
edwards,=20
washington], [4, giles, wellington], [5, childers, bristol], [6, adams, =
durban],=20
[7, fellowes, melbourne], [8, harrington, los_angeles], [9, ince, =
toronto], [10,=20
bourne, london]]</DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Hope you guys can help.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Regards.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Ken.</FONT></DIV></BODY></HTML>
------=_NextPart_000_0005_01C26DE8.9A2FA850--