books.pl 991 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. % Those are the books:
  2. book(a).
  3. book(b).
  4. book(c).
  5. book(d).
  6. book(e).
  7. book(f).
  8. % This is how 'touching' works:
  9. touching(X,Y):- touching(Y,X). % touching is symmetric
  10. touching(p1,p2).
  11. touching(p2,p3).
  12. touching(p3,p4).
  13. touching(p3,p5).
  14. touching(p3,p6).
  15. touching(p4,p5).
  16. touching(p5,p6).
  17. % List all possible positions:
  18. position(a):- p1,p2,p3,p4,p5,p6.
  19. position(b):- p1,p2,p3,p4,p5,p6.
  20. position(c):- p1,p2,p3,p4,p5,p6.
  21. position(d):- p1,p2,p3,p4,p5,p6.
  22. position(e):- p1,p2,p3,p4,p5,p6.
  23. position(f):- p1,p2,p3,p4,p5,p6.
  24. % Every position has one book
  25. getBook(p1) :- a,b,c,d,e,f.
  26. getBook(p2) :- a,b,c,d,e,f.
  27. getBook(p3) :- a,b,c,d,e,f.
  28. getBook(p4) :- a,b,c,d,e,f.
  29. getBook(p5) :- a,b,c,d,e,f.
  30. getBook(p6) :- a,b,c,d,e,f.
  31. % Add your facts:
  32. not(touching(position(a),position(d))).
  33. position(e):- p5,p2.
  34. % C touches exactly two books: eventually something like aggregate_all(count, touching(e,X), Count):-2.
  35. position(c):- p2, p4,p6.
  36. touching(position(a),position(f)).
  37. touching(position(e),position(f)).