diff options
author | Case Duckworth | 2022-07-06 22:19:46 -0500 |
---|---|---|
committer | Case Duckworth | 2022-07-06 22:19:46 -0500 |
commit | cdfe94135fe8ab1f407bb5e09c3cea93ec300469 (patch) | |
tree | 899b4aa91fd88bbaf3b1008950dcf5b6bff1b1f5 /examples/hello-world.tf | |
parent | Fix other help (diff) | |
download | trainfuck-cdfe94135fe8ab1f407bb5e09c3cea93ec300469.tar.gz trainfuck-cdfe94135fe8ab1f407bb5e09c3cea93ec300469.zip |
Fix examples
Diffstat (limited to 'examples/hello-world.tf')
-rw-r--r-- | examples/hello-world.tf | 271 |
1 files changed, 28 insertions, 243 deletions
diff --git a/examples/hello-world.tf b/examples/hello-world.tf index 397bc43..227faf6 100644 --- a/examples/hello-world.tf +++ b/examples/hello-world.tf | |||
@@ -8,47 +8,47 @@ ignored, the "[" and "]" characters just have to be balanced. This | |||
8 | loop and the commands it contains are ignored because the current cell | 8 | loop and the commands it contains are ignored because the current cell |
9 | defaults to a value of 0; the 0 value causes this loop to be skipped. | 9 | defaults to a value of 0; the 0 value causes this loop to be skipped. |
10 | 10 | ||
11 | from https://en.wikipedia.org/wiki/Brainfuck#Hello_World! | 11 | from https://en.wikipedia.org/wiki/Brainfuck#Hello_World! |
12 | 12 | ||
13 | 13 | ||
14 | ALL ABOARD | 14 | ALL ABOARD |
15 | chug chug chug chug chug chug chug chug | 15 | chug chug chug chug chug chug chug chug |
16 | END OF THE LINE | 16 | END OF THE LINE |
17 | Set Cell #0 to 8 | 17 | Set Cell #0 to 8 |
18 | 18 | ||
19 | ALL ABOARD | 19 | ALL ABOARD |
20 | tickets please | 20 | tickets please |
21 | choo | 21 | choo |
22 | chug chug chug chug | 22 | chug chug chug chug |
23 | END OF THE LINE | 23 | END OF THE LINE |
24 | Add 4 to Cell #1; this will always set Cell #1 to 4 | 24 | Add 4 to Cell #1; this will always set Cell #1 to 4 |
25 | 25 | ||
26 | ALL ABOARD | 26 | ALL ABOARD |
27 | tickets please | 27 | tickets please |
28 | END OF THE LINE | 28 | END OF THE LINE |
29 | as the cell will be cleared by the loop | 29 | as the cell will be cleared by the loop |
30 | 30 | ||
31 | ALL ABOARD | 31 | ALL ABOARD |
32 | choo | 32 | choo |
33 | chug chug | 33 | chug chug |
34 | END OF THE LINE | 34 | END OF THE LINE |
35 | Add 2 to Cell #2 | 35 | Add 2 to Cell #2 |
36 | 36 | ||
37 | ALL ABOARD | 37 | ALL ABOARD |
38 | choo | 38 | choo |
39 | chug chug chug | 39 | chug chug chug |
40 | END OF THE LINE | 40 | END OF THE LINE |
41 | Add 3 to Cell #3 | 41 | Add 3 to Cell #3 |
42 | 42 | ||
43 | ALL ABOARD | 43 | ALL ABOARD |
44 | choo | 44 | choo |
45 | chug chug chug | 45 | chug chug chug |
46 | END OF THE LINE | 46 | END OF THE LINE |
47 | Add 3 to Cell #4 | 47 | Add 3 to Cell #4 |
48 | 48 | ||
49 | ALL ABOARD | 49 | ALL ABOARD |
50 | choo | 50 | choo |
51 | chug | 51 | chug |
52 | END OF THE LINE | 52 | END OF THE LINE |
53 | Add 1 to Cell #5 | 53 | Add 1 to Cell #5 |
54 | 54 | ||
@@ -57,55 +57,55 @@ choo choo | |||
57 | choo choo | 57 | choo choo |
58 | choo choo | 58 | choo choo |
59 | choo choo | 59 | choo choo |
60 | chugga | 60 | chugga |
61 | END OF THE LINE | 61 | END OF THE LINE |
62 | Decrement the loop counter in Cell #1 | 62 | Decrement the loop counter in Cell #1 |
63 | 63 | ||
64 | ALL ABOARD | 64 | ALL ABOARD |
65 | your ticket please | 65 | your ticket please |
66 | END OF THE LINE | 66 | END OF THE LINE |
67 | Loop until Cell #1 is zero; number of iterations is 4 | 67 | Loop until Cell #1 is zero; number of iterations is 4 |
68 | 68 | ||
69 | ALL ABOARD | 69 | ALL ABOARD |
70 | choo | 70 | choo |
71 | chug | 71 | chug |
72 | END OF THE LINE | 72 | END OF THE LINE |
73 | Add 1 to Cell #2 | 73 | Add 1 to Cell #2 |
74 | 74 | ||
75 | ALL ABOARD | 75 | ALL ABOARD |
76 | choo | 76 | choo |
77 | chug | 77 | chug |
78 | END OF THE LINE | 78 | END OF THE LINE |
79 | Add 1 to Cell #3 | 79 | Add 1 to Cell #3 |
80 | 80 | ||
81 | ALL ABOARD | 81 | ALL ABOARD |
82 | choo | 82 | choo |
83 | chugga | 83 | chugga |
84 | END OF THE LINE | 84 | END OF THE LINE |
85 | Subtract 1 from Cell #4 | 85 | Subtract 1 from Cell #4 |
86 | 86 | ||
87 | ALL ABOARD | 87 | ALL ABOARD |
88 | choo | 88 | choo |
89 | choo | 89 | choo |
90 | chug | 90 | chug |
91 | END OF THE LINE | 91 | END OF THE LINE |
92 | Add 1 to Cell #6 | 92 | Add 1 to Cell #6 |
93 | 93 | ||
94 | ALL ABOARD | 94 | ALL ABOARD |
95 | tickets please choo choo | 95 | tickets please choo choo |
96 | your ticket please | 96 | your ticket please |
97 | END OF THE LINE | 97 | END OF THE LINE |
98 | Move back to the first zero cell you find; this will | 98 | Move back to the first zero cell you find; this will |
99 | be Cell #1 which was cleared by the previous loop | 99 | be Cell #1 which was cleared by the previous loop |
100 | 100 | ||
101 | ALL ABOARD | 101 | ALL ABOARD |
102 | choo choo | 102 | choo choo |
103 | chugga | 103 | chugga |
104 | END OF THE LINE | 104 | END OF THE LINE |
105 | Decrement the loop Counter in Cell #0 | 105 | Decrement the loop Counter in Cell #0 |
106 | 106 | ||
107 | ALL ABOARD | 107 | ALL ABOARD |
108 | your ticket please | 108 | your ticket please |
109 | END OF THE LINE | 109 | END OF THE LINE |
110 | Loop until Cell #0 is zero; number of iterations is 8 | 110 | Loop until Cell #0 is zero; number of iterations is 8 |
111 | 111 | ||
@@ -118,18 +118,18 @@ Pointer : ^ | |||
118 | ALL ABOARD | 118 | ALL ABOARD |
119 | choo | 119 | choo |
120 | choo | 120 | choo |
121 | click | 121 | click |
122 | END OF THE LINE | 122 | END OF THE LINE |
123 | Cell #2 has value 72 which is 'H' | 123 | Cell #2 has value 72 which is 'H' |
124 | 124 | ||
125 | ALL ABOARD | 125 | ALL ABOARD |
126 | choo | 126 | choo |
127 | chugga chugga chugga click | 127 | chugga chugga chugga click |
128 | END OF THE LINE | 128 | END OF THE LINE |
129 | Subtract 3 from Cell #3 to get 101 which is 'e' | 129 | Subtract 3 from Cell #3 to get 101 which is 'e' |
130 | 130 | ||
131 | ALL ABOARD | 131 | ALL ABOARD |
132 | chug chug chug chug chug chug chug clickety click chug chug chug click | 132 | chug chug chug chug chug chug chug clickety click chug chug chug click |
133 | 133 | ||
134 | END OF THE LINE | 134 | END OF THE LINE |
135 | Likewise for 'llo' from Cell #3 | 135 | Likewise for 'llo' from Cell #3 |
@@ -137,252 +137,37 @@ END OF THE LINE | |||
137 | ALL ABOARD | 137 | ALL ABOARD |
138 | choo | 138 | choo |
139 | choo | 139 | choo |
140 | click | 140 | click |
141 | END OF THE LINE | 141 | END OF THE LINE |
142 | Cell #5 is 32 for the space | 142 | Cell #5 is 32 for the space |
143 | 143 | ||
144 | ALL ABOARD | 144 | ALL ABOARD |
145 | choo choo | 145 | choo choo |
146 | chugga clickety | 146 | chugga clickety |
147 | END OF THE LINE | 147 | END OF THE LINE |
148 | Subtract 1 from Cell #4 for 87 to give a 'W' | 148 | Subtract 1 from Cell #4 for 87 to give a 'W' |
149 | 149 | ||
150 | ALL ABOARD | 150 | ALL ABOARD |
151 | choo choo | 151 | choo choo |
152 | clickety | 152 | clickety |
153 | END OF THE LINE | 153 | END OF THE LINE |
154 | Cell #3 was set to 'o' from the end of 'Hello' | 154 | Cell #3 was set to 'o' from the end of 'Hello' |
155 | 155 | ||
156 | ALL ABOARD | 156 | ALL ABOARD |
157 | chug chug chug click chugga chugga chugga chugga chugga chugga clickety | 157 | chug chug chug click chugga chugga chugga chugga chugga chugga clickety |
158 | chugga chugga chugga chugga chugga chugga chugga chugga click | 158 | chugga chugga chugga chugga chugga chugga chugga chugga click |
159 | END OF THE LINE | 159 | END OF THE LINE |
160 | Cell #3 for 'rl' and 'd' | 160 | Cell #3 for 'rl' and 'd' |
161 | 161 | ||
162 | ALL ABOARD | 162 | ALL ABOARD |
163 | choo | 163 | choo |
164 | choo | 164 | choo |
165 | chug click | 165 | chug click |
166 | END OF THE LINE | 166 | END OF THE LINE |
167 | Add 1 to Cell #5 gives us an exclamation point | 167 | Add 1 to Cell #5 gives us an exclamation point |
168 | 168 | ||
169 | ALL ABOARD | 169 | ALL ABOARD |
170 | choo | 170 | choo |
171 | chug chug click | 171 | chug chug click |
172 | END OF THE LINE | 172 | END OF THE LINE |
173 | And finally a newline from Cell #6 | 173 | And finally a newline from Cell #6 |
174 | ROT13 in Brainfuck | ||
175 | from https://en.wikipedia.org/wiki/Brainfuck#ROT13 | ||
176 | |||
177 | |||
178 | |||
179 | |||
180 | ALL ABOARD | ||
181 | chugga clack chug tickets please | ||
182 | END OF THE LINE | ||
183 | Read first character and start outer character reading loop | ||
184 | |||
185 | ALL ABOARD | ||
186 | chugga tickets please | ||
187 | END OF THE LINE | ||
188 | Skip forward if character is 0 | ||
189 | |||
190 | ALL ABOARD | ||
191 | choo | ||
192 | choo | ||
193 | chug chug chug chug tickets please choo | ||
194 | chug chug chug chug chug chug chug chug | ||
195 | choo choo | ||
196 | chugga your ticket please | ||
197 | END OF THE LINE | ||
198 | Set up divisor (32) for division loop | ||
199 | (MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero) | ||
200 | |||
201 | ALL ABOARD | ||
202 | choo choo | ||
203 | chug choo choo | ||
204 | chugga tickets please | ||
205 | END OF THE LINE | ||
206 | Set up dividend (x minus 1) and enter division loop | ||
207 | |||
208 | ALL ABOARD | ||
209 | choo | ||
210 | chug choo | ||
211 | chug choo | ||
212 | chugga tickets please choo | ||
213 | choo | ||
214 | choo | ||
215 | your ticket please | ||
216 | END OF THE LINE | ||
217 | Increase copy and remainder / reduce divisor / Normal case: skip forward | ||
218 | |||
219 | ALL ABOARD | ||
220 | choo choo | ||
221 | tickets please tickets please choo | ||
222 | chug choo choo | ||
223 | chugga your ticket please choo | ||
224 | choo | ||
225 | chug choo | ||
226 | your ticket please | ||
227 | |||
228 | END OF THE LINE | ||
229 | Special case: move remainder back to divisor and increase quotient | ||
230 | |||
231 | ALL ABOARD | ||
232 | choo choo | ||
233 | choo choo | ||
234 | choo choo | ||
235 | choo choo | ||
236 | choo choo | ||
237 | chugga | ||
238 | END OF THE LINE | ||
239 | Decrement dividend | ||
240 | |||
241 | ALL ABOARD | ||
242 | your ticket please | ||
243 | END OF THE LINE | ||
244 | End division loop | ||
245 | |||
246 | ALL ABOARD | ||
247 | your ticket please choo | ||
248 | choo | ||
249 | choo | ||
250 | tickets please chugga your ticket please chug | ||
251 | END OF THE LINE | ||
252 | End skip loop; zero former divisor and reuse space for a flag | ||
253 | |||
254 | ALL ABOARD | ||
255 | choo | ||
256 | chugga chugga tickets please chugga tickets please choo choo | ||
257 | chugga choo | ||
258 | chug chug chug | ||
259 | tickets please chugga your ticket please your ticket please your ticket please | ||
260 | choo choo | ||
261 | tickets please | ||
262 | END OF THE LINE | ||
263 | Zero that flag unless quotient was 2 or 3; zero quotient; check flag | ||
264 | |||
265 | ALL ABOARD | ||
266 | chug chug chug chug chug chug chug chug chug chug chug chug choo choo | ||
267 | tickets please | ||
268 | |||
269 | END OF THE LINE | ||
270 | If flag then set up divisor (13) for second division loop | ||
271 | (MEMORY LAYOUT: zero copy dividend divisor remainder quotient zero zero) | ||
272 | |||
273 | ALL ABOARD | ||
274 | choo | ||
275 | chugga tickets please choo | ||
276 | chug choo | ||
277 | choo | ||
278 | your ticket please | ||
279 | END OF THE LINE | ||
280 | Reduce divisor; Normal case: increase remainder | ||
281 | |||
282 | ALL ABOARD | ||
283 | choo | ||
284 | tickets please chug tickets please choo choo | ||
285 | chug choo | ||
286 | chugga your ticket please choo | ||
287 | chug | ||
288 | choo | ||
289 | choo | ||
290 | your ticket please | ||
291 | END OF THE LINE | ||
292 | Special case: increase remainder / move it back to divisor / increase quotient | ||
293 | |||
294 | ALL ABOARD | ||
295 | choo choo | ||
296 | choo choo | ||
297 | choo choo | ||
298 | choo choo | ||
299 | choo choo | ||
300 | chugga | ||
301 | END OF THE LINE | ||
302 | Decrease dividend | ||
303 | |||
304 | ALL ABOARD | ||
305 | your ticket please | ||
306 | END OF THE LINE | ||
307 | End division loop | ||
308 | |||
309 | ALL ABOARD | ||
310 | choo | ||
311 | choo | ||
312 | tickets please choo choo | ||
313 | chug choo | ||
314 | chugga your ticket please | ||
315 | END OF THE LINE | ||
316 | Add remainder back to divisor to get a useful 13 | ||
317 | |||
318 | ALL ABOARD | ||
319 | choo | ||
320 | tickets please | ||
321 | END OF THE LINE | ||
322 | Skip forward if quotient was 0 | ||
323 | |||
324 | ALL ABOARD | ||
325 | chugga tickets please | ||
326 | END OF THE LINE | ||
327 | Decrement quotient and skip forward if quotient was 1 | ||
328 | |||
329 | ALL ABOARD | ||
330 | chugga choo choo | ||
331 | choo choo | ||
332 | tickets please chugga your ticket please choo | ||
333 | choo | ||
334 | |||
335 | END OF THE LINE | ||
336 | Zero quotient and divisor if quotient was 2 | ||
337 | |||
338 | ALL ABOARD | ||
339 | your ticket please choo choo | ||
340 | choo choo | ||
341 | tickets please choo choo | ||
342 | choo choo | ||
343 | chugga choo | ||
344 | choo | ||
345 | chugga your ticket please choo | ||
346 | choo | ||
347 | |||
348 | END OF THE LINE | ||
349 | Zero divisor and subtract 13 from copy if quotient was 1 | ||
350 | |||
351 | ALL ABOARD | ||
352 | your ticket please choo choo | ||
353 | choo choo | ||
354 | tickets please choo choo | ||
355 | choo choo | ||
356 | chug choo | ||
357 | choo | ||
358 | chugga your ticket please | ||
359 | END OF THE LINE | ||
360 | Zero divisor and add 13 to copy if quotient was 0 | ||
361 | |||
362 | ALL ABOARD | ||
363 | your ticket please | ||
364 | END OF THE LINE | ||
365 | End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3) | ||
366 | |||
367 | ALL ABOARD | ||
368 | choo choo | ||
369 | tickets please chugga your ticket please | ||
370 | END OF THE LINE | ||
371 | Clear remainder from first division if second division was skipped | ||
372 | |||
373 | ALL ABOARD | ||
374 | choo choo | ||
375 | click tickets please chugga your ticket please | ||
376 | END OF THE LINE | ||
377 | Output ROT13ed character from copy and clear it | ||
378 | |||
379 | ALL ABOARD | ||
380 | choo choo | ||
381 | chugga clack chug | ||
382 | END OF THE LINE | ||
383 | Read next character | ||
384 | |||
385 | ALL ABOARD | ||
386 | your ticket please | ||
387 | END OF THE LINE | ||
388 | End character reading loop | ||