Advertisement
skb50bd

CSE365_01

Jan 20th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.93 KB | None | 0 0
  1. % Exercise 1
  2. loves(romeo, juliet).
  3. loves(juliet, romeo) :- loves(romeo, juliet).
  4.  
  5. % Exercise 2
  6. male(albert).
  7. male(bob).
  8. male(bill).
  9. male(carl).
  10. male(charlie).
  11. male(dan).
  12. male(edward).
  13.  
  14. female(alice).
  15. female(betsy).
  16. female(diana).
  17.  
  18. % Exercise 3
  19. happy(albert).
  20. happy(alice).
  21. happy(bob).
  22. happy(bill).
  23. with_albert(alice).
  24.  
  25. runs(albert) :- happy(albert).
  26. dances(alice) :- happy(alice), with_albert(alice).
  27.  
  28. % Exercise 4
  29. does_alice_dance :- dances(alice), write('When Alice is happy and with Albert, she dances').
  30.  
  31. % Exercise 5
  32. near_water(bob).
  33. swims(bob) :- happy(bob), near_water(bob).
  34.  
  35. % Exercise 6
  36. parent(albert, bob).
  37. parent(albert, betsy).
  38. parent(albert, bill).
  39.  
  40. parent(alice, bob).
  41. parent(alice, betsy).
  42. parent(alice, bill).
  43.  
  44. parent(bob, carl).
  45. parent(bob, charlie).
  46.  
  47. % Exercise 7
  48. get_grandchild :-
  49.     parent(albert, X),
  50.     parent(X, Y),
  51.     write('Alberts grandchildren are: '),
  52.     write(Y), nl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement