ploua. % parinte(Copil, Parinte) parinte(gheorghe, ion). parinte(gheorghe, ana). parinte(vasile, gheorghe). parinte(vasile, florica). % ?- parinte(gheorghe, ion). % ?- parinte(gheorghe, X). % ?- parinte(gheorghe, _). % ?- parinte(X, Y). % ?- parinte(florica, X). % ?- parinte(florica, _). % bunic(Nepot, Bunic) bunic(X, Y) :- parinte(X, Z), parinte(Z, Y). % ?- bunic(Nepot, Bunic) % Alice came across a lion and a unicorn in a forest of forgetfulness. % Those two are strange beings. % The lion lies every Monday, Tuesday and Wednesday % and the other days he speaks the truth. % The unicorn lies on Thursdays, Fridays and Saturdays, % however the other days of the week he speaks the truth. % Lion: Yesterday I was lying. % Unicorn: So was I. % Which day did they say that? yesterday(mon, sun). yesterday(tue, mon). yesterday(wed, tue). yesterday(thu, wed). yesterday(fri, thu). yesterday(sat, fri). yesterday(sun, sat). lies(lion, [mon, tue, wed]). lies(unicorn, [thu, fri, sat]). % Animal spune azi (Today) ca ieri a mintit saysItLiedYesterday(Animal, Today) :- yesterday(Today, Yesterday), lies(Animal, DaysLies), % obtine DaysLies not(member(Today, DaysLies)), % azi minte member(Yesterday, DaysLies). saysItLiedYesterday(Animal, Today) :- yesterday(Today, Yesterday), lies(Animal, DaysLies), member(Today, DaysLies), not(member(Yesterday, DaysLies)). % solutia sol(Today) :- saysItLiedYesterday(lion, Today), saysItLiedYesterday(unicorn, Today). % myMember(+Elem, +Lista) myMember(_, []) :- fail. % lista vida nu poate contine elementul. Aceasta linie poate sa lipseasca. % myMember(E, [H|_]) :- E == H. myMember(E, [E|_]). % elementul este primul element din lista myMember(E, [H|T]) :- E \= H, myMember(E, T). % elementul nu este primul din lista. % incL(+Lin, -Lout) incL([], []). %incL([H|T], LO) :- H1 is H + 1, incL(T, T1), LO = [H1|T1]. incL([H|T], [H1|T1]) :- H1 is H + 1, incL(T, T1).