Voting

Category

esoteric language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Brainfuck

(original version)

Date:05/30/05
Author:Andrew Paczkowski
URL:n/a
Comments:13
Info:n/a
Score: (3.70 in 239 votes)
##########################
###
### 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

VersionAuthorDateCommentsRate
Exact and complete lyricsRaphaël Bois03/07/081
lean and meanAki Rossi06/29/073
slightly improved versionMark Hurd07/01/050

Comments

>>  PuppE said on 05/18/05 00:07:20

PuppE o.O very "special" ...

>>  Rune Berge said on 05/29/05 11:58:46

Rune Berge Unfortunately it says "1 bottles" and it has an extra verse which doesn't really belong in the song:
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

>>  Keymaker said on 05/29/05 22:28:24

Keymaker If anyone's interested, here's my version of 99 bottles of beer, written in brainfuck:
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). ;)

>>  andy paczkowski said on 05/30/05 07:04:20

andy paczkowski I've just read your comments and I fixed up the code (though it's now longer) and cleared out some stupid errors I made such as using "<[<]" instead of just "[<]." Here's the printout of the last 2 verses:

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!

>>  MaxD said on 07/06/05 07:00:01

MaxD hah, brainfuck is the most hilarious language, how did you ever spend the time learning how to do that?

>>  TheDeathArt said on 08/04/05 00:49:46

TheDeathArt Hehe, well 2 friends of mine have made some more.

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

>>  Aki Rossi said on 05/16/06 15:41:00

Aki Rossi Here's another version with a slightly different approach. It's also "full-featured", but is much smaller, uses fewer cells and supports arbitrarily large beer shelfs (within cell storage limitations of the interpreter).

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.

>>  matt said on 10/23/06 15:51:42

matt Now thats what I call a proper language!

>>  gusc said on 04/11/07 22:29:24

gusc To Aki Rossi: Now that's what I call an OPTIMIZATION!! Chears mate!

>>  Andre said on 04/16/07 11:34:37

Andre The hell?????? - just...why? Why? WHAT??

>>  Mama's Boy said on 06/21/07 15:42:38

Mama's Boy How can I show my mom this site, when it says Fuck right on the tops list? :(

>>  crazzy said on 10/04/07 07:32:09

crazzy nice code, but i prefer assembly and c++... maybe i write somthing that instead of interpret compiles the shit and makes it self-executable...

>>  FunkyTim said on 12/18/07 16:08:14

FunkyTim crazzy: Compiled code is great, but just because a language is interpreted doesn't mean it is a bad language. For example, Perl is a very powerful language that is used by millions of coders around the world, and surprise! It is completely interpreted. Just something to think about.

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!

Name:

eMail:

URL:

Security Code:
  
Comment: