You are on page 1of 2

NAME: EDWIN NYARURI ONYWOKI

REG. NO: S13/15352/16


COMP 325 : LOGIC PROGRAMMING ASSIGNMENT

1. People can also be related by kinship relationship predicates (father, mother, child,
uncle, cousin, stepfather, half-brother, grandfather, etc.). Develop a knowledgebase
that will enable us query the relationship highlighted.
father(john,joseph).
father(john,james).
father(john,mary).
father(joseph,kim).
father(james,mercy).
father(kevin,jones).
mother(ann,kim).
married(ann,kevin).
female(mary).
male(kevin).
male(james).
male(john).
male(jones).
parent(X,Y):-father(X,Y);mother(X,Y).
child(X,Y):-parent(Y,X).
brother(X,Y):-parent(Z,Y),parent(Z,X),male(X).
sister(X,Y):-parent(Z,Y),parent(Z,X),female(X).
aunt(X,Y):-sister(X,Z),parent(Z,Y).
uncle(X,Y):-brother(X,Z),parent(Z,Y).
cousin(X,Y):-child(X,Z),uncle(Z,Y).
stepfather(X,Y):-mother(Z,Y),married(Z,X),not(father(X,Y)).
halfbrother(X,Y):-child(X,Z),stepfather(Z,Y),male(X).
grandfather(X,Y):-parent(X,Z),parent(Z,Y),male(X).
2. Write a prolog code to print values 1 to 10 using recursion.
print_numbers(10) :- write(10),!.
print_numbers(X) :- write(X),nl,Next is X + 1, print_numbers(Next).
3. Write a program to solve the stable marriage problem.
married(paul,tina).
married(ham,audrey).
married(harry,betty).
married(kim,becky).
married(dan,skylar).
married(liam,leah).
prefers(paul,audrey).
prefers(audrey,paul).
prefers(harry,becky).
prefers(kim,betty).
prefers(dan,leah).
prefers(leah,dan).
prefers(liam,skylar).
prefers(skylar,liam).
unstable_marriage(X,Y):-married(X,Y),prefers(X,Z),prefers(Z,X).
stable_marriage(X,Y):-not(unstable_marriage(X,Y)).

You might also like