


% facts
kid(joanne).
kid(lou).
kid(ralph).
kid(winnie).

imaginaryFriend(grizzly_bear).
imaginaryFriend(moose).
imaginaryFriend(seal).
imaginaryFriend(zebra).

adventure(circus).
adventure(rock_band).
adventure(spaceship).
adventure(train).


solve :-
    adventure(JoannesAdventure), adventure(LousAdventure), adventure(RalphsAdventure),
    adventure(WinniesAdventure),
    all_different([JoannesAdventure, LousAdventure, RalphsAdventure, WinniesAdventure]),

    imaginaryFriend(JoannesAnimal), imaginaryFriend(LousAnimal), imaginaryFriend(RalphsAnimal),
    imaginaryFriend(WinniesAnimal),
    all_different([JoannesAnimal, LousAnimal, RalphsAnimal, WinniesAnimal]),

    ImaginaryFriends = [
                        animal(joanne, JoannesAdventure, JoannesAnimal),
                        animal(lou, LousAdventure , LousAnimal),
                        animal(ralph, RalphsAdventure, RalphsAnimal),
                        animal(winnie, WinniesAdventure, WinniesAnimal)
                        ],



    % 1. the seal (who isnt the creation of either joanne or Lau) neither rode.
    % to the moon in a spaceship nor took a trip around the world on a magic train

    \+ member(animal(joanne, _, seal), ImaginaryFriends),
    \+ member(animal(lou, _, seal), ImaginaryFriends),
    \+ member(animal(_, spaceship, seal), ImaginaryFriends),
    \+ member(animal(_, train, seal), ImaginaryFriends),


    % 2. Joanne's imaginary friend (who isnt the Grizzly bear) went to the curcus.

    \+ member(animal(joanne, _ ,grizzly_bear), ImaginaryFriends),
       member(animal(joanne, circus, _), ImaginaryFriends),

    % 3. Winnies imaginary friend is a zebra.

       member(animal(winnie, _, zebra), ImaginaryFriends),


    % 4. The grizzly bear didn't board the spaceship to the moon.

      \+ member(animal(grizzly_bear, spaceship, _), ImaginaryFriends),

      tell(joanne, JoannesAdventure, JoannesAnimal),
      tell(lou, LousAdventure , LousAnimal),
      tell(ralph, RalphsAdventure, RalphsAnimal),
      tell(winnie, WinniesAdventure, WinniesAnimal).

      tell(Kid, Adventure, Animal) :- write(Kid) , write(" went on a adventure to "),
      write(Adventure), write(" with the "), write(Animal), 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([_]).
