-
Notifications
You must be signed in to change notification settings - Fork 0
/
8 9 23.pl
165 lines (126 loc) · 3.7 KB
/
8 9 23.pl
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
% 8 9 23
% 23 algs needed
% ["Medicine","MEDICINE by Lucian Green Panic attack prevented by deep breathing and sutra 1 of 4.txt",0,algorithms,"3. I prepared to taste the computational egg. I did this by writing the Egg song argument. First, I groped the egg. Second, I tasted the dark chocolate. Third, I revealed the prize. In this way, I prepared to taste the computational egg by writing the Egg song argument."]
%object(egg,white).
%object(sphere,(red,(yellow,(white,(purple,brown),black,(green,white))))).
object(sphere,(((null,4,null),2,(null,5,null)),1,(null,3,(null,6,null)))).
% taste(sphere,dfs_pre_order,L).
% L = [1, 2, 4, 5, 3, 6].
% taste(sphere,dfs_in_order,L).
% L = [4, 2, 5, 1, 3, 6].
% taste(sphere,dfs_post_order,L).
% L = [4, 5, 2, 6, 3, 1].
object(cube,(((null,"red",null),"yellow",(null,"blue",null)),"white",(null,"green",(null,"purple",null)))).
% taste(cube,dfs_pre_order,L).
% L = ["white", "yellow", "red", "blue", "green", "purple"].
% taste(cube,dfs_in_order,L).
% L = ["red", "yellow", "blue", "white", "green", "purple"].
% taste(cube,dfs_post_order,L).
% L = ["red", "blue", "yellow", "purple", "green", "white"].
%taste(egg,dfs_pre_order,Items).
taste(Object,Method,Items1) :-
object(Object,Items2),
traverse(Method,Items2,Items1).
traverse(dfs_pre_order,Items1,Items2) :-
dfs_pre_order(Items1,[],Items2).
dfs_pre_order((Item7,Item4,Item8),Items2,Items3) :-
append(Items2,[Item4],Items6),
dfs_pre_order(Item7,Items6,Items8),
dfs_pre_order(Item8,Items8,Items3),!.
dfs_pre_order(null,Items2,Items2) :- !.
% append(Items2,[Item1],Items3).
traverse(dfs_in_order,Items1,Items2) :-
dfs_in_order(Items1,[],Items2).
dfs_in_order((Item7,Item4,Item8),Items2,Items3) :-
dfs_in_order(Item7,Items2,Items8),
append(Items8,[Item4],Items6),
dfs_in_order(Item8,Items6,Items3),!.
dfs_in_order(null,Items2,Items2) :- !.
% append(Items2,[Item1],Items3).
traverse(dfs_post_order,Items1,Items2) :-
dfs_post_order(Items1,[],Items2).
dfs_post_order((Item7,Item4,Item8),Items2,Items3) :-
dfs_post_order(Item7,Items2,Items8),
dfs_post_order(Item8,Items8,Items6),
append(Items6,[Item4],Items3),!.
dfs_post_order(null,Items2,Items2) :- !.
% 18 done
:-include('../listprologinterpreter/la_maths.pl').
% pretty_print(sphere, dfs_pre_order).
/*
1
2
4
5
3
6
pretty_print(sphere, dfs_in_order).
4
2
5
1
3
6
pretty_print(sphere, dfs_post_order).
4
5
2
6
3
1
pretty_print(cube, dfs_pre_order).
white
yellow
red
blue
green
purple
pretty_print(cube, dfs_in_order).
red
yellow
blue
white
green
purple
pretty_print(cube, dfs_post_order).
red
blue
yellow
purple
green
white
*/
pretty_print(Object,Method) :-
object(Object,Items2),
pretty_print(Method,Items2).
pretty_print(dfs_pre_order,Items1) :-
pretty_print_dfs_pre_order(Items1,0).
pretty_print_dfs_pre_order((Item7,Item4,Item8),N) :-
numbers(N,1,[],Ns),
findall(_,(member(_,Ns),write(" ")),_),
writeln(Item4),
N1 is N+1,
pretty_print_dfs_pre_order(Item7,N1),
pretty_print_dfs_pre_order(Item8,N1),!.
pretty_print_dfs_pre_order(null,_) :- !.
pretty_print(dfs_in_order,Items1) :-
pretty_print_dfs_in_order(Items1,0).
pretty_print_dfs_in_order((Item7,Item4,Item8),N) :-
N1 is N+1,
pretty_print_dfs_in_order(Item7,N1),
numbers(N,1,[],Ns),
findall(_,(member(_,Ns),write(" ")),_),
writeln(Item4),
pretty_print_dfs_in_order(Item8,N1),!.
pretty_print_dfs_in_order(null,_) :- !.
pretty_print(dfs_post_order,Items1) :-
pretty_print_dfs_post_order(Items1,0).
pretty_print_dfs_post_order((Item7,Item4,Item8),N) :-
N1 is N+1,
pretty_print_dfs_post_order(Item7,N1),
pretty_print_dfs_post_order(Item8,N1),
numbers(N,1,[],Ns),
findall(_,(member(_,Ns),write(" ")),_),
writeln(Item4),!.
pretty_print_dfs_post_order(null,_) :- !.
% 34