% facts
sister(abigal).
sister(brenda).
sister(mary).
sister(paula).
sister(tara).

month(febuary).
month(march).
month(june).
month(july).
month(december).

day(sunday).
day(monday).
day(wednesday).
day(friday).
day(saturday).


solve :-
  month(AbigalsMonth), month(BrendasMonth), month(MarysMonth),
   month(PaulasMonth), month(TarasMonth),
   all_different([AbigalsMonth, BrendasMonth, MarysMonth, PaulasMonth
   TarasMonth]),

   day(AbigalsDay), day(BrendasDay), day(MarysDay),
   day(PaulasDay), day(TarasDay),
   all_different([AbigalsDay, BrendasDay, MarysDay, PaulasDay, TarasDay]),


   Birthdays = [
                birthday(abigal, AbigalsMonth, AbigalsDay),
                birthday(brenda, BrendasMonth, BrendasDay),
                birthday(mary, MarysMonth, MarysDay),
                birthday(paula, PaulasMonth, PaulasDay),
                birthday(tara, TarasMonth, TarasDay)
                ],


              member(paula, march, _),
              \+ member(paula, _ , saturday),
              \+ member(abigal, _, friday),
              \+ member(abigal, _, wednesday),

              % the girl with th birthday on monday was born earlyer in the year than
              % brenda & mary



              \+ member(tara, febuary, _),
              ((member(tara, _, saturday)) ; (member(tara, _, sunday))),

              \+ member(mary, december, _),
              ((member(mary, _, saturday)) ; (member(mary, _ , sunday)),

              member(_ , june , sunday),

              % tara was born before brenda
              \+ member(tara, _, friday),
              \+ member(mary /+ july),


              tell(abigal, AbigalsMonth, AbigalsDay),
              tell(brenda, BrendasMonth, BrendasDay),
              tell(mary, MarysMonth, MarysDay),
              tell(paula, PaulasMonth, PaulasDay),
              tell(tara, TarasMonth, TarasDay).

          tell(Sister, Month, Day) :- write(Sister), write(" was born in "), write(Month), write(" on the "),
              write(day), 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([_]).
