Subject: Re: interesting problem

From: Paul Sephton <[email-masked]>
Date: Tue, 16 May 2000 10:29:06 +0200 (GMT+0200)

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

> 
> > Date: Mon, 15 May 2000 15:46:21 +0200 (GMT+0200)
> > From: Paul Sephton <[email-masked]>
> > 
> > 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 ([email-masked])                               INET Development
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ever wondered if jumping out of the frying pan might actually be refreshing?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~