From paul@inet.co.za  Tue May 16 08:39:17 2000
Received: from exchange_rbk02.inet.co.za (exchange-rbk02.inet.co.za [196.38.91.22])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id IAA16620
	for <prolog@swi.psy.uva.nl>; Tue, 16 May 2000 08:39:15 +0200 (MET DST)
Received: from pdev.inet.co.za ([196.14.60.35]) by exchange_rbk02.inet.co.za with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21)
	id K81Z3RHG; Tue, 16 May 2000 08:40:46 +0200
Date: Tue, 16 May 2000 10:29:06 +0200 (GMT+0200)
From: Paul Sephton <paul@inet.co.za>
To: "Pascal J. Bourguignon" <pjb@imaginet.fr>
cc: prolog@swi.psy.uva.nl
Subject: Re: interesting problem
In-Reply-To: <200005160019.CAA20119@triton.local.net>
Message-ID: <Pine.LNX.3.91.1000516102445.19793C-100000@pdev.inet.co.za>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Tue, 16 May 2000, Pascal J. Bourguignon wrote:

> 
> > Date: Mon, 15 May 2000 15:46:21 +0200 (GMT+0200)
> > From: Paul Sephton <paul@inet.co.za>
> > 
> > I _love_ these problems, and couldn't resist.  If this is a homework 
> > assignment, then so be it...
> 
> 
> Well, my own solution is somewhat different (it still gives equivalent
> results,  of course).   I would  like to  have the  opinion  of prolog
> experts  about  style, advantages,  inconvenients  and performance  of
> these solutions.

<solution follows>

Very similar to what I ended up with eventually.  To my knowledge, there 
is not much overhead associated with storing the facts in lists, but the 
real reason I did it like that was because I was lazy.  My latest 
solution is a little more readable than my previous iteration:

language([english,joe,chris,emily,heidi,isacc]).
language([french,beth,gong,isacc]).
language([korean,chris,dongoon,fred,jane]).
language([chinese,gong,heidi,jane,kenny]).
female_list([beth,emily,heidi,chris,jane]).

speaks(Lang, Person) :- language([Lang|People]), member(Person, People).
female(Person)       :- female_list(Females), !, member(Person, Females).
male(Person)         :- speaks(_, Person), not(female(Person)).

sex(Person, male)   :-  
  findall(P, male(P), PList), list_to_set(PList, PSet), !,member(Person, PSet).
sex(Person, female) :-  female(Person).

seatable(Left, Person) :-
  sex(Person, female), speaks(Lang, Person),  speaks(Lang, Left),  
  Left \= Person,  sex(Left, male).
seatable(Left, Person) :-
  sex(Person, male), speaks(Lang, Person), speaks(Lang, Left), Left \= Person.

seat(Person, Seated, _)        :- memberchk(Person, Seated), !, fail.
seat(Person, Seated, [Person]) :- length(Seated, 10), seatable(joe, Person).
seat(Person, Seated, [Person|T]) :-
  seatable(Left, Person), seat(Left, [Person|Seated], T).
  
report([H])   :- !, write(H), nl.
report([H|T]) :- writef("%w-", [H]), report(T).
  
go :- seat(joe, [], X), report(X), fail.

% ?- go.
% joe-chris-dongoon-fred-jane-kenny-heidi-gong-beth-isacc-emily
% joe-chris-fred-dongoon-jane-kenny-heidi-gong-beth-isacc-emily
% joe-emily-isacc-beth-gong-heidi-kenny-jane-dongoon-fred-chris
% joe-emily-isacc-beth-gong-heidi-kenny-jane-fred-dongoon-chris
% 
% Yes
_____________________________________________________________________________
Paul Sephton (paul@inet.co.za)                               INET Development
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ever wondered if jumping out of the frying pan might actually be refreshing?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

