Removing files from data analysis directory
[ou-summer-of-code-2017.git] / 02-lifts / part2.bf
1 set cell 1 to 61 # exit
2 set cell 2 to 94 minus 61=33 # up
3 set cell 3 to 118 minus 94=24 # down
4
5 cell 5 for currently at an exit: 1 if at an exit 0 otherwise
6
7 set cell 6 to 0 (current level)
8 set cell 7 to for height above ground min zero
9 set cell 8 to 0 (highest exit)
10 cell 9 for input
11 cell 10 for whether input has been dealt with: 0 for yes 1 for no
12 cell 11 for whether dealt with the height above zero cell
13 reserve cell 12 and higher for scratch
14
15
16 >+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++>++++++++++++++++++++++++
17
18
19 read character into cell 9
20 >>>>>>,
21
22
23
24 while cell 9 != 0 # have an input
25 [
26 set cell 10 to 1
27 >[-]+
28
29 # clear cells 4 and 0
30 <<<<<<[-]<<<<[-]>
31 # copy cell 1 to cell 0 using cell 4
32 [-<+>>>>+<<<]
33 >>>[-<<<+>>>]
34 <<<<
35
36 subtract cell 0 from cell 9
37 [->>>>>>>>>-<<<<<<<<<]
38 >>>>>>>>>
39
40 while cell 9 != 0 # we're not at an exit
41 [
42 set cell 10 to 0
43 >[-]
44
45 copy cell 2 to cell 0 using cell 4
46 <<<<<<<<[-<<+>>>>+<<]
47 >>[-<<+>>]
48 <<<<
49
50 subtract cell 0 from cell 9
51 [->>>>>>>>>-<<<<<<<<<]
52 >>>>>
53
54 set cell 5 to 1
55 [-]+
56 >>>>
57
58
59 while cell 9 != 0 # we're going down
60 [
61 clear cell 5
62 <<<<[-]
63 copy cell 7 to cell 11 using cell 12
64 >>[->>>>+>+<<<<<]
65 >>>>>[-<<<<<+>>>>>]
66
67 cell 12 is zero
68
69 while cell 11 != 0 # above ground
70 <
71 [
72 set cell 12 to 1
73 >[-]+
74
75 clear cell 11
76 <[-]
77 end
78 ] 11
79
80 while cell 12 != 0
81 >
82 [
83 decrement cell 7
84 <<<<<-
85
86 set cell 12 to zero
87 >>>>>[-]
88 end
89 ] 12
90
91 <<<<<<
92 decrement cell 6
93 -
94
95 have now dealt with the input so clear cell 9
96 >>>[-]
97 end
98 ] 9
99
100
101 while cell 5 != 0 # we're going up
102 <<<<
103 [
104 clear cell 5
105 [-]
106
107
108 # set cell 12 to 0
109 >>>>>>>[-]
110
111 ### if 6 == 0 or 7 != 0
112 ### set cell 12 to 1
113
114 # copy cell 6 to cell 11 using cell 12
115 <<<<<<[->>>>>+>+<<<<<<]
116 >>>>>>[-<<<<<<+>>>>>>]
117
118 set cell 12 to 1
119 [-]+
120
121 while cell 11 != 0
122 <
123 [
124 clear cell 12
125 >[-]
126
127 set cell 11 to 0
128 <[-]
129 end 11
130 ] 11
131
132
133
134 # copy cell 7 to cell 11 using cell 13
135 <<<<[->>>>+>>+<<<<<<]
136 >>>>>>[-<<<<<<+>>>>>>]
137
138 # while cell 11 != 0
139 <<
140 [
141 set cell 12 to 1
142 >[-]+
143
144 set cell 11 to 0
145 <[-]
146
147 # end 11
148 ] 11
149 # add cell 12 to cell 7
150 >[-<<<<<+>>>>>]
151
152 # increment cell 6
153 <<<<<<+
154 <
155 end
156 ] 5
157
158 have now dealt with the non exit node
159 clear cell 9
160 >>>>
161 [-]
162 end
163 ] 9
164
165 while cell 10 != 0 # at an exit
166 >
167 [
168 copy cell 7 to cell 12 using cell 13 (highest)
169 <<<[->>>>>+>+<<<<<<]
170 >>>>>>[-<<<<<<+>>>>>>]
171
172 while cell 12 != 0 (above ground level)
173 <
174 [
175 copy cell 8 to cell 11 using cell 13 (highest)
176 <<<<[->>>+>>+<<<<<]
177 >>>>>[-<<<<<+>>>>>]
178
179 cell 13 is zero
180
181 ### subtract 11 from 12 ensuring 12 gte 0
182 ### add 12 to 8
183
184 while cell 11 != 0
185 <<
186 [
187 copy cell 12 to cell 14 using cell 15
188 >[->>+>+<<<]
189 >>>[-<<<+>>>]
190
191 while cell 14 != 0
192 <
193 [
194 set cell 13 to 1
195 <[-]+
196 decrement cell 14
197 >-
198 end
199 ] 14
200 while cell 13 != 0
201 <
202 [
203 decrement cell 12
204 <-
205 decrement cell 13
206 >-
207 end
208 ] 13
209
210 decrement cell 11
211 <<-
212 end
213 ] 11
214
215 >[-<<<<+>>>>]
216 add cell 12 to cell 8
217 ] 12
218 <<
219 clear 10
220 [-]
221 ] 10
222
223
224
225 read character into cell 9
226 <,
227 end
228 ] 9
229
230 output cell 8
231 <.
232
233