Subject: Re: interesting problem

From: Paul Sephton <[email-masked]>
Date: Mon, 15 May 2000 15:46:21 +0200 (GMT+0200)

I _love_ these problems, and couldn't resist.  If this is a homework 
assignment, then so be it...

:-dynamic seated/2.

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

speaks(Lang, Person) :- language([Lang|People]), member(Person, People).

female(beth).
female(emily).
female(heidi).
female(chris).
female(jane).

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, not(seated(Left, _)), sex(Left, male).
seatable(Left, Person) :-
  sex(Person, male), speaks(Lang, Person), speaks(Lang, Left), 
  Left \= Person, not(seated(Left, _)).

seat(joe) :- seated(_, joe).
seat(Person) :-
  not(seated(_, Person)), seatable(Left, Person), not(seated(Left, _)),
  assert(seated(Left, Person)), seat(Left).
seat(Person) :- retract(seated(Person, _)), fail.
  
report :- 
  findall([Left, Right], seated(Left, Right), List),
  length(List, 11), report(List).
  
report([]) :- nl.
report([[_, Right]|T]) :- writef("%w-", [Right]), report(T).
  
go :-
  retractall(seated(_,_)), seat(joe), report, fail.
go.

% ?- 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

Have fun
Paul
_____________________________________________________________________________
Paul Sephton ([email-masked])                               INET Development
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ever wondered if jumping out of the frying pan might actually be refreshing?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~