Advertisement
tzoonami

Untitled

Sep 26th, 2013
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 2.59 KB | None | 0 0
  1. child(john,sue).  child(john,sam).
  2. child(jane,sue).  child(jane,sam).
  3. child(sue,george). child(sue,gina).
  4. child(jeff,george). child(jeff,martha).
  5. child(fred,jane).  child(fred,joe).
  6. child(britt,john). child(britt,beth).
  7. child(frank,britt). child(frank,brandon).
  8. child(katie,fred).  child(katie,morgan).
  9. child(bill,jeff).  child(bill,nora).
  10. child(beth,matt).  child(beth,ann).
  11. child(joe,matt).  child(joe,ann).
  12. child(harry,frank). child(harry,felicity).
  13.  
  14. male(john). male(sam). male(george). male(fred).
  15. male(joe). male(frank). male(brandon). male(jeff).
  16. male(bill). male(matt). male(harry).
  17. female(sue). female(jane). female(june). female(martha).
  18. female(gina). female(britt). female(beth). female(katie).
  19. female(morgan). female(nora). female(ann). female(felicity).
  20.  
  21. parent(Y,X) :- child(X,Y).
  22. father(Y,X) :- child(X,Y), male(Y).
  23. opp_sex(X,Y) :- male(X), female(Y).
  24. opp_sex(Y,X) :- male(X), female(Y).
  25. grand_father(X,Z) :- father(X,Y), parent(Y,Z).
  26. mother(Y,X) :- child(X,Y), female(Y).
  27. grand_parent(X,Z) :- parent(X,Y), parent(Y,Z).
  28. great_grand_mother(X,Z) :- mother(X,W), parent(W,Y), parent(Y,Z).
  29. sibling(X,Y) :- parent(Z,X), parent(Z,Y), \+ X=Y.
  30. brother(X,Y) :- sibling(X,Y), male(X). %X is a brother of Y
  31. sister(X,Y) :- sibling(X,Y), female(X). %X is a sister of Y
  32. half_sibling(X,Y) :- sibling(X,Y), parent(Z,X), parent(A,Y), parent(B,X), parent(C,Y), \+ A=Z, \+ B=C, \+ A=B, \+Z=B.
  33. full_sibling(X,Y) :- sibling(X,Y), parent(Z,X), parent(Z,Y), parent(A,X), parent(A,Y), \+ A=Z.
  34. first_cousin(X,Y) :- parent(Z,X), parent(A,Y), sibling(A,Z), \+A=Z.
  35. second_cousin(X,Y) :- parent(Z,X), parent(A,Y), first_cousin(A,Z), \+A=Z.
  36. half_first_cousin(X,Y) :- parent(Z,X), parent(A,Y), half_sibling(A,Z), \+A=Z.
  37. double_first_cousin(X,Y) :- parent(Z,X), parent(A,Y), parent(B,X), parent(C,Y), sibling(A,Z), sibling(B,C), \+Z=A, \+B=C, \+Z=B, \+A=B.
  38. first_cousin_twice_removed(X,Y) :- grand_parent(Z,X), first_cousin(Z,Y),\+ half_first_cousin(Z,Y).
  39. first_cousin_twice_removed(X,Y) :- first_cousin_twice_removed(Y,X).
  40. descendant(X,Y) :- child(X,Y).
  41. descendant(X,Y) :- child(X,Z), descendant(Z,Y), \+ Y=Z.
  42. ancestor(X,Y) :- descendant(Y,X).
  43. cousin(X,Y) :- parent(Z,X), parent(A,Y), sibling(Z,A), \+A=Z.
  44. cousin(X,Y) :- parent(Z,X), parent(A,Y), cousin(Z,A), \+A=Z.
  45. closest_common_ancestor(X,Y,Z) :- ancestor(X,Y), ancestor(X,Z), child(A,X), \+ancestor(A,X), \+ ancestor(A,Y), \+A=X, \+ Y=Z.
  46. write_child(X,Y) :- write(X), write(' is a child of '), write(Y), nl.
  47. write_descendant_chain(X,Y) :- child(X,Y), write_child(X,Y).
  48. write_descendant_chain(X,Y) :- child(X,Z), \+ Y=Z, write_child(X,Z), write_descendant_chain(Z,Y).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement