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