AI Codes
AI Codes
2.2 Append a list L2 at the end of another list L1 and put the resultant list in L3
Ans:
% If L1 is empty, resultant list will be equal to L2 (base case)
append_list([], L2, L2).
append_list([X | L1], L2, [X | L3]) :-
append_list(L1, L2, L3).
Output:
Output:
4. Write a program for usage of rules in Prolog. Create a family tree program to
include following rules.
1. M is the mother of P if she is a parent of P and is female.
2. F is the father of P if he is a parent of P and is male.
3. X is a sibling of Y if they both have the same parent.
4. Then add rules for grandparents, uncle-aunt, sister and brother.
Ans:
% Facts defining family relationships
parent(john, alice).
parent(john, bob).
parent(mary, alice).
parent(mary, bob).
parent(bob, charlie).
parent(bob, daisy).
parent(alice, edward).
parent(alice, fiona).
male(john).
male(bob).
male(charlie).
male(edward).
female(mary).
female(alice).
female(daisy).
female(fiona).