% Imaginary Friends Problem

%Facts

friends(grizzlybear).
friends(moose).
friends(seal).
friends(zebra).

child(joanne).
child(luo).
child(ralph).
child(winne).

adventure(circus).
adventure(rockband).
adventure(spaceship).
adventure(train).


 % If the head of the list is in the tail, fail.
 all_different([Head|Tail]) :- member(Head, Tail), !, fail.
 % Otherwise, check the tail of the list.
 all_different([_|Tail]) :- all_different(Tail).
 % If there's only one thing in the list, it's fine.
 all_different([_]).



solve :-
    adventure(JA), adventure(LA), adventure(RA), adventure(WA),
    all_different([JA,LA,RA,WA]),

    friends(JI),friends(LI),friends(RI),friends(WI),
    all_different([JI,LI,RI,WI]),

    %stroy(ChildName,WhosAdventure,ImgenaryFriend),

    Storys = [story(joanne,JA,JI),
              story(luo,LA,LI),
              story(ralph,RA,RI),
              story(winne,WA,WI)],

    %1. The seal(who isn't the creation of eaither Joanne or Lou) neither rode to the moon in a space ship nor took a trip ardound the world on a magic train.

    \+ member(story(joanne,_,seal),Storys),
    \+ member(story(luo,_,seal),Storys),
    \+ member(story(_,spaceship,seal),Storys),
    \+ member(story(_,train,seal),Storys),

    %2. Joanne's Imaginary friend (who isn't the grizzly bear) went to the Circus.

    \+ member(story(joanne,_,grizzlybear),Storys),
     member(story(joanne,circus,_),Storys),


    %3. Winnie's imaginary Freind is a zebra.

     member(story(winne,_,zebra),Storys),

    %4. The grizzly bear didn't board the spaceship to the moon.

    \+ member(story(_,spaceship,grizzlybear),Storys),

    tell(joanne,JA,JI),
    tell(luo,LA,LI),
    tell(ralph,RA,RI),
    tell(winne,WA,WI).

tell(Child,Adv,Imgfrnd) :- write(Child), write(' wrote about the '),
    write(Imgfrnd), write(' and there '),
    write(Adv), write(' adventure.').


