%Children
child(joanne).
child(lou).
child(ralph).
child(winnie).

%Imaginary Friends
friend(bear).
friend(moose).
friend(seal).
friend(zebra).

%Adventures
adventure(circus).
adventure(band).
adventure(spaceship).
adventure(train).

solve :-
	friend(JoanneFriend),
	friend(LouFriend),
	friend(RalphFriend),
	friend(WinnieFriend),
	different([JoanneFriend, LouFriend, RalphFriend, WinnieFriend]),
	
	adventure(JoanneAdventure),
	adventure(LouAdventure),
	adventure(RalphAdventue),
	adventure(WinnieAdventure),
	different([JoanneAdventure, LouAdventure, RalphAdventue, WinnieAdventure]),
	
	Stories = [ story(joanne, JoanneFriend, JoanneAdventure), story(lou, LouFriend, LouAdventure),
				story(ralph, RalphFriend, RalphAdventue), story(winnie, WinnieFriend, WinnieAdventure)],
				
	%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, bear, _), Stories),
	member(story(joanne, _, circus), Stories),
	
	%Rule 3
	member(story(winnie, zebra, _), Stories),
	
	%Rule 4
	\+ member(story(_, bear, spaceship), Stories),
	
	tell(joanne, JoanneFriend, JoanneAdventure),
	tell(lou, LouFriend, LouAdventure),
	tell(ralph, RalphFriend, RalphAdventue),
	tell(winnie, WinnieFriend, WinnieAdventure).
	
tell(Child, Friend, Adventure) :- write(Child), write(' wrote a book about a '), write(Friend), write(' on a '), write(Adventure), write(' adventure.'), nl.

different([Head | Tail]) :- member(Head, Tail), !, fail.
different([_|Tail]) :- different(Tail).
different([_]).	