Prolog Program to insert different relationships in terms of facts and
rules:
parent(john,tom).
parent(john,bob). parent(john,sue). parent(mary,bob). parent(mary,sue).
parent(tom,mercy). parent(bob,clue). parent(bob,ray). parent(sue,clue).
parent(sue,ray).
parent(sou,vedik). parent(ved,harsh). parent(harsh,vijay).
parent(vijay,milan).
parent(milan,vishal). parent(vishal,chakki).
male(john).
male(tom). male(ray). male(bob). female(mary). female(mercy). female(sue).
female(clue).
grandp(X,Y):-
parent(X,A),parent(A,Y).
brother(X,Y):-
parent(A,Y),parent(A,X),male(X).
sister(X,Y):-
parent(A,Y)parent(A,X),female(X).
uncle(X,Y):-
parent(A,X),brother(Y,A).
aunty(X,Y):-
parent(A,X),sister(Y,A).
cousins(X,Y):-
uncle(X,A),parent(A,Y), Y\=X.
ansc(X,Y):-
parent(X,Y).
ansc(X,Y):-
ansc(A,Y),parent(X,A).
Input:
parent(X,tom).
parent(X,mercy). parent(X,harsh). parent(X,vijay). male(mary).
No comments:
Post a Comment