propella / prolog

a prolog

This URL has Read+Write access

prolog / demo.prolog
100644 53 lines (41 sloc) 0.737 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
% comment
 
child(sazae, namihei).
child(sazae, fune).
child(katsuo, namihei).
child(katsuo, fune).
child(wakame, namihei).
child(wakame, fune).
child(tara, sazae).
child(tara, masuo).
 
?- child(X, fune).
;
;
;
 
grandChild(X, Z) :- child(X, Y), child(Y, Z).
?- grandChild(X, Y).
;
;
 
t(1).
t(2).
t(3).
perm(X, Y, Z) :- t(X), t(Y), t(Z).
?- perm(X, Y, X).
;
;
;
;
;
;
;
;
;
 
append([], Ys, Ys).
append([X|Xs], Ys, [X|Zs]) :- append(Xs, Ys, Zs).
 
?- append([a,b,c], [d,e], X).
 
reverse([],[]).
reverse([X|Xs], Zs) :- reverse(Xs, Ys), append(Ys, [X], Zs).
 
?-reverse([a,b,c,d,e], X).
 
acReverse(Xs, Ys) :- acReverse(Xs, [], Ys).
acReverse([X|Xs], Acc, Ys) :- acReverse(Xs, [X|Acc], Ys).
acReverse([], Ys, Ys).
 
?-acReverse([a,b,c,d,e], X).