% Solution to Challenge 1

% Facts
friend(grizzly_bear).
friend(moose).
friend(seal).
friend(zebra).

person(joanne).
person(lou).
person(ralph).
person(winnie).

adventure(circus).
adventure(rock_band).
adventure(spaceship).
adventure(train).


solve :-
    adventure(JoanneAdventure), adventure(LouAdventure), adventure(RalphAdventure),
    adventure(WinnieAdventure),
    all_different([JoanneAdventure, LouAdventure, RalphAdventure, WinnieAdventure]),
    
    friend(JoanneFriend), friend(LouFriend), friend(RalphFriend), friend(WinnieFriend),
    all_different([JoanneFriend, LouFriend, RalphFriend, WinnieFriend]),
    
    
            
    Stories = [ story(joanne, JoanneFriend, JoanneAdventure),
                story(lou, LouFriend,LouAdventure),
                story(ralph, RalphFriend, RalphAdventure),
                story(winnie, WinnieFriend, WinnieAdventure) ],
              
              
    % 1. 
    \+ member(story(joanne, seal, _), Stories),
    \+ member(story(lou, seal, _), Stories),
    \+ member(story( _, seal, spaceship), Stories),
    \+ member(story( _, seal, train), Stories),


    % 2.
    \+ member(story(joanne, grizzly_bear, _), Stories),
    member(story(joanne, _, circus), Stories),
    
    % 3.
   member(story(winnie, zebra, _), Stories),
    
    % 4.
    \+ member(story(_, grizzly_bear, spaceship), Stories),
    
   
    tell(joanne, JoanneFriend, JoanneAdventure),
    tell(lou, LouFriend, LouAdventure),
    tell(ralph, RalphFriend, RalphAdventure),
    tell(winnie, WinnieFriend, WinnieAdventure).

tell(Who, With, Where) :- write(Who), write(' went to the '), write(Where), write(' with their imaginary friend '), write(With), 
write('.'), nl.

%tell(To, From, Tie) :- write('Mr. '), write(To), write(' got the '), write(Tie),
    %write(' tie from his '), write(From), write('.'), nl.
    
% 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([_]).