xref: /netbsd-src/sys/external/bsd/sljit/dist/doc/tutorial/99bottles.bf (revision 99e10043c2d890154986b9f0cfb10c84949ba483)
1##########################
2###
3### Severely updated version!
4### (now says "1 bottle" and
5### contains no extra "0" verse)
6###
7##########################
8### 99 Bottles of Beer ###
9### coded in Brainfuck ###
10### with explanations  ###
11##########################
12#
13# This Bottles of Beer program
14# was written by Andrew Paczkowski
15# Coder Alias: thepacz
16# three_halves_plus_one@yahoo.com
17#####
18
19>                            0 in the zeroth cell
20+++++++>++++++++++[<+++++>-] 57 in the first cell or "9"
21+++++++>++++++++++[<+++++>-] 57 in second cell or "9"
22++++++++++                   10 in third cell
23>+++++++++                    9 in fourth cell
24
25##########################################
26### create ASCII chars in higher cells ###
27##########################################
28
29>>++++++++[<++++>-]               " "
30>++++++++++++++[<+++++++>-]        b
31+>+++++++++++[<++++++++++>-]       o
32++>+++++++++++++++++++[<++++++>-]  t
33++>+++++++++++++++++++[<++++++>-]  t
34>++++++++++++[<+++++++++>-]        l
35+>++++++++++[<++++++++++>-]        e
36+>+++++++++++++++++++[<++++++>-]   s
37>++++++++[<++++>-]                " "
38+>+++++++++++[<++++++++++>-]       o
39++>++++++++++[<++++++++++>-]       f
40>++++++++[<++++>-]                " "
41>++++++++++++++[<+++++++>-]        b
42+>++++++++++[<++++++++++>-]        e
43+>++++++++++[<++++++++++>-]        e
44>+++++++++++++++++++[<++++++>-]    r
45>++++++++[<++++>-]                " "
46+>+++++++++++[<++++++++++>-]       o
47>+++++++++++[<++++++++++>-]        n
48>++++++++[<++++>-]                " "
49++>+++++++++++++++++++[<++++++>-]  t
50++++>++++++++++[<++++++++++>-]     h
51+>++++++++++[<++++++++++>-]        e
52>++++++++[<++++>-]                " "
53++>+++++++++++++[<+++++++++>-]     w
54+>++++++++++++[<++++++++>-]        a
55>++++++++++++[<+++++++++>-]        l
56>++++++++++++[<+++++++++>-]        l
57>+++++[<++>-]                      LF
58++>+++++++++++++++++++[<++++++>-]  t
59+>++++++++++++[<++++++++>-]        a
60+++>+++++++++++++[<++++++++>-]     k
61+>++++++++++[<++++++++++>-]        e
62>++++++++[<++++>-]                " "
63+>+++++++++++[<++++++++++>-]       o
64>+++++++++++[<++++++++++>-]        n
65+>++++++++++[<++++++++++>-]        e
66>++++++++[<++++>-]                " "
67>++++++++++[<++++++++++>-]         d
68+>+++++++++++[<++++++++++>-]       o
69++>+++++++++++++[<+++++++++>-]     w
70>+++++++++++[<++++++++++>-]        n
71>++++++++[<++++>-]                " "
72+>++++++++++++[<++++++++>-]        a
73>+++++++++++[<++++++++++>-]        n
74>++++++++++[<++++++++++>-]         d
75>++++++++[<++++>-]                " "
76++>+++++++++++[<++++++++++>-]      p
77+>++++++++++++[<++++++++>-]        a
78+>+++++++++++++++++++[<++++++>-]   s
79+>+++++++++++++++++++[<++++++>-]   s
80>++++++++[<++++>-]                " "
81+>+++++++++++++[<++++++++>-]       i
82++>+++++++++++++++++++[<++++++>-]  t
83>++++++++[<++++>-]                " "
84+>++++++++++++[<++++++++>-]        a
85>+++++++++++++++++++[<++++++>-]    r
86+>+++++++++++[<++++++++++>-]       o
87>+++++++++++++[<+++++++++>-]       u
88>+++++++++++[<++++++++++>-]        n
89>++++++++++[<++++++++++>-]         d
90>+++++[<++>-]                      LF
91+++++++++++++                      CR
92
93[<]>>>>      go back to fourth cell
94
95#################################
96### initiate the display loop ###
97#################################
98
99[            loop
100 <           back to cell 3
101 [            loop
102  [>]<<       go to last cell and back to LF
103  ..          output 2 newlines
104  [<]>        go to first cell
105
106 ###################################
107 #### begin display of characters###
108 ###################################
109 #
110 #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
111 #X X     b o t t l e s   o f   b e e r
112 #.>.>.>.>.>.>.>.>.>.>.>.
113 #o n   t h e   w a l l N
114 #[<]>    go to first cell
115 #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.>
116 #X X     b o t t l e s   o f   b e e r             N
117 #.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
118 #t a k e   o n e   d o w n   a n d   p a s s
119 #.>.>.>.>.>.>.>.>.>.
120 #i t   a r o u n d N
121 #####
122
123  [<]>>      go to cell 2
124  -          subtract 1 from cell 2
125  <          go to cell 1
126
127 ########################
128 ### display last line ##
129 ########################
130 #
131 #.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
132 #X X     b o t t l e s   o f   b e e r
133 #.>.>.>.>.>.>.>.>.>.>.
134 #o n   t h e   w a l l
135 #####
136
137  [<]>>>-      go to cell 3/subtract 1
138 ]            end loop when cell 3 is 0
139 ++++++++++   add 10 to cell 3
140 <++++++++++  back to cell 2/add 10
141 <-           back to cell 1/subtract 1
142 [>]<.        go to last line/carriage return
143 [<]>         go to first line
144
145########################
146### correct last line ##
147########################
148#
149#.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
150#X X     b o t t l e s   o f   b e e r
151#.>.>.>.>.>.>.>.>.>.>.
152#o n   t h e   w a l l
153#####
154
155 [<]>>>>-    go to cell 4/subtract 1
156]           end loop when cell 4 is 0
157
158##############################################################
159### By this point verses 9910 are displayed but to work   ###
160### with the lower numbered verses in a more readable way  ###
161### we initiate a new loop for verses 9{CODE} that will not    ###
162### use the fourth cell at all                             ###
163##############################################################
164
165+           add 1 to cell four (to keep it nonzero)
166<--         back to cell 3/subtract 2
167
168[            loop
169 [>]<<       go to last cell and back to LF
170 ..          output 2 newlines
171 [<]>        go to first cell
172
173 ###################################
174 #### begin display of characters###
175 ###################################
176 #
177 #>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
178 # X     b o t t l e s   o f   b e e r
179 #.>.>.>.>.>.>.>.>.>.>.>.
180 #o n   t h e   w a l l N
181 #[<]>    go to first cell
182 #>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.>
183 # X     b o t t l e s   o f   b e e r             N
184 #.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
185 #t a k e   o n e   d o w n   a n d   p a s s
186 #.>.>.>.>.>.>.>.>.>.
187 #i t   a r o u n d N
188 #####
189
190 [<]>>       go to cell 2
191 -           subtract 1 from cell 2
192
193 ########################
194 ### display last line ##
195 ########################
196 #
197 #.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
198 #X     b o t t l e s   o f   b e e r
199 #.>.>.>.>.>.>.>.>.>.>.
200 #o n   t h e   w a l l
201 #####
202
203 [<]>>>-     go to cell 3/subtract 1
204]            end loop when cell 3 is 0
205+            add 1 to cell 3 to keep it nonzero
206
207[>]<.        go to last line/carriage return
208[<]>         go to first line
209
210########################
211### correct last line ##
212########################
213#
214#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>.>
215# X     b o t t l e    o f   b e e r
216#.>.>.>.>.>.>.>.>.>.>.<<<<.
217#o n   t h e   w a l l
218#####
219
220[>]<<       go to last cell and back to LF
221..          output 2 newlines
222[<]>        go to first line
223
224#########################
225### the final verse    ##
226#########################
227#
228#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>.>
229# X     b o t t l e    o f   b e e r
230#.>.>.>.>.>.>.>.>.>.>.>.
231#o n   t h e   w a l l N
232#[<]>        go to first cell
233#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.>
234# X     b o t t l e    o f   b e e r             N
235#.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
236#t a k e   o n e   d o w n   a n d   p a s s
237#.>.>.>.>.>.>.>.>.>.
238#i t   a r o u n d N
239#[>]<        go to last line
240#<<<.<<.<<<.
241#   n  o
242#[<]>>>>     go to fourth cell
243#>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
244#   b o t t l e s   o f   b e e r
245#.>.>.>.>.>.>.>.>.>.>.>.
246#o n   t h e   w a l l N
247#####fin##