blob: 227faf689dca40d6ebc87452fe5148ffad973fe9 (
plain)
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
166
167
168
169
170
171
172
173
|
This program prints "Hello World!" and a newline to the screen, its
length is 106 active command characters. [It is not the shortest.]
This loop is an "initial comment loop", a simple way of adding a comment
to a BF program such that you don't have to worry about any command
characters. Any ".", ",", "+", "-", "<" and ">" characters are simply
ignored, the "[" and "]" characters just have to be balanced. This
loop and the commands it contains are ignored because the current cell
defaults to a value of 0; the 0 value causes this loop to be skipped.
from https://en.wikipedia.org/wiki/Brainfuck#Hello_World!
ALL ABOARD
chug chug chug chug chug chug chug chug
END OF THE LINE
Set Cell #0 to 8
ALL ABOARD
tickets please
choo
chug chug chug chug
END OF THE LINE
Add 4 to Cell #1; this will always set Cell #1 to 4
ALL ABOARD
tickets please
END OF THE LINE
as the cell will be cleared by the loop
ALL ABOARD
choo
chug chug
END OF THE LINE
Add 2 to Cell #2
ALL ABOARD
choo
chug chug chug
END OF THE LINE
Add 3 to Cell #3
ALL ABOARD
choo
chug chug chug
END OF THE LINE
Add 3 to Cell #4
ALL ABOARD
choo
chug
END OF THE LINE
Add 1 to Cell #5
ALL ABOARD
choo choo
choo choo
choo choo
choo choo
chugga
END OF THE LINE
Decrement the loop counter in Cell #1
ALL ABOARD
your ticket please
END OF THE LINE
Loop until Cell #1 is zero; number of iterations is 4
ALL ABOARD
choo
chug
END OF THE LINE
Add 1 to Cell #2
ALL ABOARD
choo
chug
END OF THE LINE
Add 1 to Cell #3
ALL ABOARD
choo
chugga
END OF THE LINE
Subtract 1 from Cell #4
ALL ABOARD
choo
choo
chug
END OF THE LINE
Add 1 to Cell #6
ALL ABOARD
tickets please choo choo
your ticket please
END OF THE LINE
Move back to the first zero cell you find; this will
be Cell #1 which was cleared by the previous loop
ALL ABOARD
choo choo
chugga
END OF THE LINE
Decrement the loop Counter in Cell #0
ALL ABOARD
your ticket please
END OF THE LINE
Loop until Cell #0 is zero; number of iterations is 8
The result of this is:
Cell no : 0 1 2 3 4 5 6
Contents: 0 0 72 104 88 32 8
Pointer : ^
ALL ABOARD
choo
choo
click
END OF THE LINE
Cell #2 has value 72 which is 'H'
ALL ABOARD
choo
chugga chugga chugga click
END OF THE LINE
Subtract 3 from Cell #3 to get 101 which is 'e'
ALL ABOARD
chug chug chug chug chug chug chug clickety click chug chug chug click
END OF THE LINE
Likewise for 'llo' from Cell #3
ALL ABOARD
choo
choo
click
END OF THE LINE
Cell #5 is 32 for the space
ALL ABOARD
choo choo
chugga clickety
END OF THE LINE
Subtract 1 from Cell #4 for 87 to give a 'W'
ALL ABOARD
choo choo
clickety
END OF THE LINE
Cell #3 was set to 'o' from the end of 'Hello'
ALL ABOARD
chug chug chug click chugga chugga chugga chugga chugga chugga clickety
chugga chugga chugga chugga chugga chugga chugga chugga click
END OF THE LINE
Cell #3 for 'rl' and 'd'
ALL ABOARD
choo
choo
chug click
END OF THE LINE
Add 1 to Cell #5 gives us an exclamation point
ALL ABOARD
choo
chug chug click
END OF THE LINE
And finally a newline from Cell #6
|