
child(joanne).
child(lou).
child(ralph).
child(winnie).

animal(grizzly_bear).
animal(moose).
animal(seal).
animal(zebra).

adventure(circus).
adventure(rock_Band).
adventure(spaceship).
adventure(train).



solve :-
	animal(Joanne_animal), animal(Lou_animal), animal(Ralph_animal), animal(Winnie_animal),

	all_different([Joanne_animal,Lou_animal,Ralph_animal,Winnie_animal]),

	adventure(Joanne_adventure),adventure(Lou_adventure),adventure(Ralph_adventure),adventure(Winnie_adventure),

	all_different([Joanne_adventure,Lou_adventure,Ralph_adventure,Winnie_adventure]),

	Stories = [story(joanne,Joanne_animal,Joanne_adventure),
				story(lou,Lou_animal,Lou_adventure),
				story(ralph,Ralph_animal,Ralph_adventure),
				story(winnie,Winnie_animal,Winnie_adventure) ],
	% Rule 1
	\+ member(story(joanne,seal,_),Stories),
	\+ member(story(lou,seal,_),Stories),
	\+ member(story(_,seal,spaceship),Stories),
	\+ member(story(_,seal,train),Stories),

	% Rule 2
	\+member(story(joanne,grizzly_bear,_),Stories),
	member(story(joanne,_,circus),Stories),

	% Rule 3
	member(story(winnie,zebra,_),Stories),

	% Rule 4
	\+member(story(_,grizzly_bear,spaceship),Stories),

	tell(joanne,Joanne_animal,Joanne_adventure),
    tell(lou,Lou_animal,Lou_adventure),
    tell(ralph,Ralph_animal,Ralph_adventure),
    tell(winnie,Winnie_animal,Winnie_adventure).
    
tell(Who,What,Where) :- write(Who), write(' told the story about '), write(What),
    write(' going '), write(Where), 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([_]).