sister(abigail).
sister(brenda).
sister(mary).
sister(paula).
sister(tara).

month(february).
month(march).
month(june).
month(july).
month(december).

day(sunday).
day(monday).
day(wednesday).
day(friday).
day(saturday).

solve :-
	month(AbigailMonth),
	month(BrendaMonth),
	month(MaryMonth),
	month(PaulaMonth),
	month(TaraMonth),
	different([AbigailMonth, BrendaMonth, MaryMonth, PaulaMonth, TaraMonth]),
	
	day(AbigailDay),
	day(BrendaDay),
	day(MaryDay),
	day(PaulaDay),
	day(TaraDay),
	different([AbigailDay, BrendaDay, MaryDay, PaulaDay, TaraDay]),
	
	Birthdays = [birthday(abigail, AbigailMonth, AbigailDay),
				birthday(brenda, BrendaMonth, BrendaDay),
				birthday(mary, MaryMonth, MaryDay),
				birthday(paula, PaulaMonth, PaulaDay),
				birthday(tara, TaraMonth, TaraDay)],
			
	%Rule 1
	member(birthday(paula, march, _), Birthdays),
	\+ member(birthday(paula, _, saturday), Birthdays),
	\+ member(birthday(abigail, _, friday), Birthdays),
	\+ member(birthday(abigail, _, wednesday), Birthdays),
	
	%Rule 2
	\+ member(birthday(brenda, february, _), Birthdays),
	\+ member(birthday(mary, february, _), Birthdays),
	\+ member(birthday(brenda, _, monday), Birthdays),
	\+ member(birthday(mary, _, monday), Birthdays),
	
	%Rule 3
	\+ member(birthday(tara, february, _), Birthdays),
	(member(birthday(tara, _, saturday), Birthdays) ; member(birthday(tara, _, sunday), Birthdays)),
	
	%Rule 4
	\+ member(birthday(mary, december, _), Birthdays),
	\+ (member(birthday(mary, _, monday), Birthdays);
		member(birthday(mary, _, wednesday), Birthdays);
		member(birthday(mary, _, friday), Birthdays)),
	member(birthday(_, june, sunday), Birthdays),
	
	%Rule 5
	\+ member(birthday(brenda, _, friday), Birthdays),
	\+ member(birthday(mary, july, _), Birthdays),
	\+ member(birthday(tara, december, _), Birthdays),
	
	tell(abigail, AbigailMonth, AbigailDay),
	tell(brenda, BrendaMonth, BrendaDay),
	tell(mary, MaryMonth, MaryDay),
	tell(paula, PaulaMonth, PaulaDay),
	tell(tara, TaraMonth, TaraDay).
	
tell(Name, Month, Day) :- 
	write(Name), write("'s birthday is on a "), write(Day), write(' in '), write(Month), write('.'), nl.
	
different([Head | Tail]) :- member(Head, Tail), !, fail.
different([_ | Tail]) :- different(Tail).
different([_]).

