Language Brainfuck
(original version)
| Date: | 05/30/05 |
| Author: | Andrew Paczkowski |
| URL: | n/a |
| Comments: | 13 |
| Info: | n/a |
| Score: |
##########################
###
### Severely updated version!
### (now says "1 bottle" and
### contains no extra "0" verse)
###
##########################
### 99 Bottles of Beer ###
### coded in Brainfuck ###
### with explanations ###
##########################
#
# This Bottles of Beer program
# was written by Andrew Paczkowski
# Coder Alias: thepacz
# three_halves_plus_one@yahoo.com
#####
> 0 in the zeroth cell
+++++++>++++++++++[<+++++>-] 57 in the first cell or "9"
+++++++>++++++++++[<+++++>-] 57 in second cell or "9"
++++++++++ 10 in third cell
>+++++++++ 9 in fourth cell
##########################################
### create ASCII chars in higher cells ###
##########################################
>>++++++++[<++++>-] " "
>++++++++++++++[<+++++++>-] b
+>+++++++++++[<++++++++++>-] o
++>+++++++++++++++++++[<++++++>-] t
++>+++++++++++++++++++[<++++++>-] t
>++++++++++++[<+++++++++>-] l
+>++++++++++[<++++++++++>-] e
+>+++++++++++++++++++[<++++++>-] s
>++++++++[<++++>-] " "
+>+++++++++++[<++++++++++>-] o
++>++++++++++[<++++++++++>-] f
>++++++++[<++++>-] " "
>++++++++++++++[<+++++++>-] b
+>++++++++++[<++++++++++>-] e
+>++++++++++[<++++++++++>-] e
>+++++++++++++++++++[<++++++>-] r
>++++++++[<++++>-] " "
+>+++++++++++[<++++++++++>-] o
>+++++++++++[<++++++++++>-] n
>++++++++[<++++>-] " "
++>+++++++++++++++++++[<++++++>-] t
++++>++++++++++[<++++++++++>-] h
+>++++++++++[<++++++++++>-] e
>++++++++[<++++>-] " "
++>+++++++++++++[<+++++++++>-] w
+>++++++++++++[<++++++++>-] a
>++++++++++++[<+++++++++>-] l
>++++++++++++[<+++++++++>-] l
>+++++[<++>-] LF
++>+++++++++++++++++++[<++++++>-] t
+>++++++++++++[<++++++++>-] a
+++>+++++++++++++[<++++++++>-] k
+>++++++++++[<++++++++++>-] e
>++++++++[<++++>-] " "
+>+++++++++++[<++++++++++>-] o
>+++++++++++[<++++++++++>-] n
+>++++++++++[<++++++++++>-] e
>++++++++[<++++>-] " "
>++++++++++[<++++++++++>-] d
+>+++++++++++[<++++++++++>-] o
++>+++++++++++++[<+++++++++>-] w
>+++++++++++[<++++++++++>-] n
>++++++++[<++++>-] " "
+>++++++++++++[<++++++++>-] a
>+++++++++++[<++++++++++>-] n
>++++++++++[<++++++++++>-] d
>++++++++[<++++>-] " "
++>+++++++++++[<++++++++++>-] p
+>++++++++++++[<++++++++>-] a
+>+++++++++++++++++++[<++++++>-] s
+>+++++++++++++++++++[<++++++>-] s
>++++++++[<++++>-] " "
+>+++++++++++++[<++++++++>-] i
++>+++++++++++++++++++[<++++++>-] t
>++++++++[<++++>-] " "
+>++++++++++++[<++++++++>-] a
>+++++++++++++++++++[<++++++>-] r
+>+++++++++++[<++++++++++>-] o
>+++++++++++++[<+++++++++>-] u
>+++++++++++[<++++++++++>-] n
>++++++++++[<++++++++++>-] d
>+++++[<++>-] LF
+++++++++++++ CR
[<]>>>> go back to fourth cell
#################################
### initiate the display loop ###
#################################
[ loop
< back to cell 3
[ loop
[>]<< go to last cell and back to LF
.. output 2 newlines
[<]> go to first cell
###################################
#### begin display of characters###
###################################
#
#.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
#X X b o t t l e s o f b e e r
#.>.>.>.>.>.>.>.>.>.>.>.
#o n t h e w a l l N
#[<]> go to first cell
#.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.>
#X X b o t t l e s o f b e e r N
#.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
#t a k e o n e d o w n a n d p a s s
#.>.>.>.>.>.>.>.>.>.
#i t a r o u n d N
#####
[<]>> go to cell 2
- subtract 1 from cell 2
< go to cell 1
########################
### display last line ##
########################
#
#.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
#X X b o t t l e s o f b e e r
#.>.>.>.>.>.>.>.>.>.>.
#o n t h e w a l l
#####
[<]>>>- go to cell 3/subtract 1
] end loop when cell 3 is 0
++++++++++ add 10 to cell 3
<++++++++++ back to cell 2/add 10
<- back to cell 1/subtract 1
[>]<. go to last line/carriage return
[<]> go to first line
########################
### correct last line ##
########################
#
#.>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
#X X b o t t l e s o f b e e r
#.>.>.>.>.>.>.>.>.>.>.
#o n t h e w a l l
#####
[<]>>>>- go to cell 4/subtract 1
] end loop when cell 4 is 0
##############################################################
### By this point verses 99\10 are displayed but to work ###
### with the lower numbered verses in a more readable way ###
### we initiate a new loop for verses 9{CODE} that will not ###
### use the fourth cell at all ###
##############################################################
+ add 1 to cell four (to keep it non\zero)
<-- back to cell 3/subtract 2
[ loop
[>]<< go to last cell and back to LF
.. output 2 newlines
[<]> go to first cell
###################################
#### begin display of characters###
###################################
#
#>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
# X b o t t l e s o f b e e r
#.>.>.>.>.>.>.>.>.>.>.>.
#o n t h e w a l l N
#[<]> go to first cell
#>.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.>
# X b o t t l e s o f b e e r N
#.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
#t a k e o n e d o w n a n d p a s s
#.>.>.>.>.>.>.>.>.>.
#i t a r o u n d N
#####
[<]>> go to cell 2
- subtract 1 from cell 2
########################
### display last line ##
########################
#
#.>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
#X b o t t l e s o f b e e r
#.>.>.>.>.>.>.>.>.>.>.
#o n t h e w a l l
#####
[<]>>>- go to cell 3/subtract 1
] end loop when cell 3 is 0
+ add 1 to cell 3 to keep it non\zero
[>]<. go to last line/carriage return
[<]> go to first line
########################
### correct last line ##
########################
#
#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>.>
# X b o t t l e o f b e e r
#.>.>.>.>.>.>.>.>.>.>.<<<<.
#o n t h e w a l l
#####
[>]<< go to last cell and back to LF
.. output 2 newlines
[<]> go to first line
#########################
### the final verse ##
#########################
#
#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>.>
# X b o t t l e o f b e e r
#.>.>.>.>.>.>.>.>.>.>.>.
#o n t h e w a l l N
#[<]> go to first cell
#>.>>>.>.>.>.>.>.>.>>.>.>.>.>.>.>.>.>>>>>>>>>>>>>.>
# X b o t t l e o f b e e r N
#.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
#t a k e o n e d o w n a n d p a s s
#.>.>.>.>.>.>.>.>.>.
#i t a r o u n d N
#[>]< go to last line
#<<<.<<.<<<.
# n o
#[<]>>>> go to fourth cell
#>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>
# b o t t l e s o f b e e r
#.>.>.>.>.>.>.>.>.>.>.>.
#o n t h e w a l l N
#####fin##
Download Source | Write Comment
Alternative Versions
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| Exact and complete lyrics | Raphaël Bois | 03/07/08 | 1 | |
| slightly improved version | Mark Hurd | 07/01/05 | 0 | |
| lean and mean | Aki Rossi | 06/29/07 | 3 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
00 bottles of beer on the wall
00 bottles of beer
take one down and pass it around
no bottles of beer on the wall
http://www.bf-hacks.org/hacks/beer.b
My version notices that to print '1 bottle' when there's only one bottle and 'no more bottles' when there's none left. As well, it doesn't print any unneeded zero-digits. When there are no tens left, it prints only the ones.
The code, however, is far from the clear and commented program you can see here -- it's a bit smaller and quite complex (for layperson, at least).
2 bottles of beer on the wall
2 bottles of beer
take one down and pass it around
1 bottle of beer on the wall
1 bottle of beer on the wall
1 bottle of beer
take one down and pass it around
no bottles of beer on the wall
I'll send it in now. Thanks for the feedback, guys!
1) Brainfork, a multithreaded version: http://www.bf.clanpogo.dk/
2) Braintwist , brainfork with pointers and code swap http://sigkill.dk/code/bf.html
See.. thats insanity
http://iki.fi/aki.rossi/bf/bottles.b
Also available as a commented version for the faint-hearted (missing for the moment are comments to the integer-to-string conversion part):
http://iki.fi/aki.rossi/bf/bottles.commented.b
The main difference here is to not spend effort in pregenerating strings, instead using a few chosen output registers to speed up generation of ASCII characters on the fly. Some care was also taken to avoid redundancy.