[comp.lang.prolog] The jobs puzzle

LAZBM@CUNYVM.CUNY.EDU (10/02/89)

 This is my solution to the jobs puzzle.
 It works, but it would be nice to write down the problem and that would
 be the solution.
 Anybody has a better solution?

/* The jobs puzzle
 * 1  There are four people roberta thelma steve and pete
 * 2  Among them,they hold eight different jobs
 * 3  Each holds exactly 2 jobs
 * 4  The jobs are:chef,guard,nurse,telephone operator,
 *        police officer(gender not implied) teacher actor boxer
 * 5  The job of nurse is held by a male
 * 6  The husband of the chef is the telephone operator
 * 7  Roberta is not the boxer
 * 8  Pete has no education past ninth grade
 * 9  Roberta, the chef and the police officer went golfing together
 */
solve:-joblist(Jlist),
       del(J1,Jlist,Jl1),del(J2,Jl1,Jl2),J1 < J2 ,hasjobs(roberta,J1,J2),
       del(J3,Jl2,  Jl3),del(J4,Jl3,Jl4),J3 < J4 ,hasjobs(thelma ,J3,J4),
       del(J5,Jl4  ,Jl5),del(J6,Jl5,Jl6),J5 < J6 ,hasjobs(steve  ,J5,J6),
       del(J7,Jl6  ,Jl7),del(J8,Jl7,Jl8),J7 < J8 ,hasjobs(pete   ,J7,J8),
       write('roberta '),write(J1),write(' '),write(J2),nl,
       write('thelma  '),write(J3),write(' '),write(J4),nl,
       write('steve   '),write(J5),write(' '),write(J6),nl,
       write('pete    '),write(J7),write(' '),write(J8),nl.

hasjobs(X,chef,police):-!,fail.      /*9 */
hasjobs(X,police,chef):-!,fail.      /*9 */
hasjobs(X,telop,chef):-!,fail.       /*6 */
hasjobs(X,chef,telop):-!,fail.       /*6 */
hasjobs(X,J1,J2):- hasjob(X,J1),
                   hasjob(X,J2).

hasjob(roberta,chef):-!,fail.       /*9 */
hasjob(roberta,police):-!,fail.     /*9 */
hasjob(pete,police):-!,fail.        /*8*/
hasjob(pete,nurse ):-!,fail.        /*8*/
hasjob(pete,teacher):-!,fail.       /*8*/
hasjob(roberta,boxer):- !,fail.     /*7*/
hasjob(X,nurse):- !,male(X).        /*5*/
hasjob(X,actor):- !,male(X).                 /* meaning of actor*/
hasjob(X,telop):-!,male(X).         /*6 */
hasjob(X,chef ):-!,not male(X).     /*6 */
hasjob(X,Y).

male(steve).
male(pete ).

/* list symbol is { } in this prolog */
joblist({chef,guard,nurse,telop,police,teacher,actor,boxer}).
del(X,{X|T},T).
del(X,{Y|T},{Y|T1}) :- del(X,T,T1).