Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

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