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:29
Info:n/a
Score: (3.49 in 374 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
bottle shapedMichal Wojciech Tarnowski11/13/100
Exact and complete lyricsRaphaël Bois03/07/084
lean and meanAki Rossi06/29/074
slightly improved versionMark Hurd07/01/051

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.

>>  Trilce said on 09/06/08 18:05:04

Trilce And there is actually a compiler for Brainfuck. It's called brainfucked but it's only for DOS (output are COM files). Hope linux users will get one soon.

>>  ruben said on 09/23/08 14:24:40

ruben the readability is great..... XD

>>  Sam Witse said on 09/24/08 14:09:20

Sam Witse Real programmers only use Brainfuck.

>>  dennis loepke said on 10/22/08 10:24:09

dennis loepke

>>  iblis said on 12/13/08 22:04:50

iblis Trilce - http://code.google.com/p/awib/

Apparently, there's been a linux compiler for quite some time. :D

>>  Trilce said on 01/08/09 02:33:34

Trilce Thanks iblis. After I comented there I got aware of awib (Also Written In Brainfuck). Incredible, it is really a compiler for Linux on i386 written ONLY IN BRAINFUCK. Of course it can compile itself.

There is also another compiler by Brian Raiter that outputs ELF format executables written in Assembler (NASM). It is particulary small (171 bytes) but It works great.
Check it out
http://www.muppetlabs.com/~breadbox/software/tiny/

>>  Matus Goljer said on 12/07/09 23:30:58

Matus Goljer Here's my latest attempt to write a Brainfuck interpret in Befunge-98, I think some of you might enjoy: http://fi.muni.cz/~xgoljer/bf.txt

>>  Laloeka said on 12/23/09 12:41:38

Laloeka Nice job, but i discovered a bug.. :P

90, 80, 70, 60, 50, 40, 30, 20 and 10 are wrong, they are displayed as:
9/, 8/, 7/, 6/, 5/, 4/, 3/, 2/ and 1/ and after that, comes the 89, 79, 69, etc..

>>  lulzbrinasaour said on 03/31/10 18:03:19

lulzbrinasaour FKING MAZING BISH

>>  Gregor Szaktilla said on 08/05/10 20:30:56

Gregor Szaktilla

>>  Maxxx said on 08/09/10 11:13:43

Maxxx Brainfuck? Wut the crap is that?

>>  chi hair online said on 09/13/10 05:12:03

chi hair online 329my
Welcome to our [b]chi hair online[/b] store to buy the [b]chi straightener[/b]. We offer you the discount chi straighteners, If you are interested in the [b]ceramic hair straighteners[/b] and CHI Digital Ceramic Hair Straightener, you can choose the best [b]chi hair straighteners[/b] here. In addition, we have many high quality discount [b]chi hair straightener[/b], we hope that you can come.

>>  xiaoxiao208 said on 09/13/10 07:57:32

xiaoxiao208 bestuggbots.net is the best ugg boots on sale store and ugg boots uk with 100% sheepskin and low price,you can buy ugg for free shipping and no sale tax include UGG Ultra Tall UGG Classic Mini UGG Classic Tall UGG Classic Cardy UGG Bailey Button UGG Bailey Button Triplet
bestuggbots.net is the best ugg boots on sale store and ugg boots uk with 100% sheepskin and low price,you can buy ugg for free shipping and no sale tax include UGG Ultra Tall UGG Classic Mini UGG Classic Tall UGG Classic Cardy UGG Bailey Button UGG Bailey Button Triplet
uggmall-uk.com provide cheap uggs and ugg boots uk, you can find ugg classic boot with High quality and competitive price include UGG bailey button, UGG classic argyle knit, UGG stripe cable knit, UGG classic tall boots, UGG classic cardy boots, UGG classic short boots, UGG ultra tall boots 5245, UGG classic mini boots, UGG Metallic Gold Classic . [PRE][/PRE]

bestuggmall.com provide ugg boots sale and Ugg boots shop, you can find Ugg 5815|5825|5803 with High quality and competitive price include ugg classic argyle knit boot ,ugg tall stripe cable knit ,UGG Bailey Button ,,UGG classic Cardy ,,ugg ultra tall boots ,classic mini ugg boots
Bestuggboots provides cheap ugg bootsugg bootsugg pink is a cute color for girls who like ugg classic tall boots.ugg classic tall boot 5815, ugg classic short boot 5825, ugg classic cardy boot, ugg classic mini boot, ugg argyle knit bootsugg ultre tall boot
Cheapuggbootonline is a ugg discount shop that you can get best cheap ugg boots.On this ugg boots shop you can find all kind of ugg boots sale,like Ugg 5815,ugg 5803 and ugg 5825,etc.ugg bailey button 5803, ugg classic tall 5815,ugg classic cardy boot,ugg classic short 5825,ugg ultre short boots,ugg ultre tall boots,ugg classic mini boot.
cheapuggbootsonsale.comprovide Ugg boots saleCheap ugg boots, you can find UGG Classic BootsUGG Classic Boots,UGG Classic Boots,Ugg Bailey Button,UGG NEW ARRIVAL,UGG Classic Tall,UGG Classic Cardy ,UGG Classic Short,UGG Ultra Short,UGG Ultra Tall,UGG Sundance,UGG Classic Mini,UGG Nightfall,UGG Handbags,UGG New Tall,Ugg New Sandals,UGG Sandals,UGG Slippers.

>>  ED Hardy Bikini said on 09/15/10 08:32:06

ED Hardy Bikini nike rifts
nike rift
nike air max
nike air rift
nike air rifts
nike rifts men
nike air max skyline
nike air max classic
nike shox rivalry
air max 90
nike air max 90
Air Max Skyline
Nike Dunk Sb
Nike Free Run+ Men
Nike Air Rift Women
Nike Shox
Nike Kid Shoes
Nike Air Max 1
Nike Air Max 87
Nike Air Max 180
Nike Air Max 2003
Nike Air Max 2009
Nike Air Max 93
Nike Air Max 95
Nike Air Max 97
Nike Air Max Classic Bw
Nike Air Max Light
Nike Air Max 88
Nike Air Max Ltd
Nike Air Max Tn
Nike Air Rift Men
Nike Air Max 90 Kids
Nike Air Max TN Kid
Nike Air Rift Kid
Nike Shox R4 Kid
Nike Shox NZ
Nike Shox OZ
Nike Shox R4
Nike Shox Rivalry R3
Nike Shox TL
Nike Shox TL3
Nike Rifts for Kids
Nike Air Rejuven8
Nike Air Force 1 Low


nike rifts
nike rift
nike air max
nike air rift
nike air rifts
nike air force
nike air jordan
nike shox
nike shox rivalry
air max 90
nike air max 90
Nike Air Rejuven8
Nike pas cher
Rift Nike
Nike Air Max Skyline
Air Max Skyline
Nike Rifts Men
Nike Shox R4
Nike Air Max TN
Nike Air Max 95
Nike Air Max 97
Nike Air Max 2009
Nike Air Max 180


Nike Rifts
Nike Rift
Nike Air Max
Nike Air Rift
Nike Air Rifts
Nike Air Force
Nike Shox OZ
Nike Shox R4
Nike Shox Rivalry
Air Max 90
Nike Air Max 90
Nike Air Rejuven8
Nike pas cher
Nike Air Rift Femme
Nike Air Max Skyline
Air Max Skyline
Nike Air Rift Homme
Nike Pas cher Livraison Gratuite
Rift Nike
Air Rift
Nike Rifts Men
Chaussure Nike Pas cher
Basket Nike Pas cher


ED Hardy
ED Hardy Clothing
Christian Audigier
ED Hardy Accessories
ED Hardy Bags
ED Hardy Handbags
ED Hardy Belts
ED Hardy Sunglasses
ED Hardy Kid's T-shirt
ED Hardy Kid Shirt
ED Hardy Kid
ED Hardy Man
ED Hardy Active Wear
ED Hardy Man Wear
ED Hardy Hoodies
ED Hardy Outerwear
ED Hhardy Man's Hoodies
ED Hardy Long Sleeves
ED Hardy Man's Sleeves
ED Hardy Shoes
ED Hardy Man's Shoes
ED Hardy T-shirts
ED Hardy Man's T-shirts
ED Hardy Swim Trunks
ED Hardy Man's Trunks
ED Hardy Women
ED Hardy Bottoms
ED Hardy Women's Bottoms
ED Hardy Women's Hoodies
ED Hardy Women's Outerwear
ED Hardy Intimates
ED Hardy Lingerie
ED Hardy Women's Sleeves
ED Hardy Sandals
ED Hardy Women's Sandals
ED Hardy Women's T-shirts
ED Hardy Swimwear
ED Hardy Bikini
ED Hardy Tanks
ED Hardy Women's Tanks
ED Hardy Knits Tops
C A Women
C A Man
r4ds

>>  Entrepreneur Ideas said on 09/16/10 20:18:21

Entrepreneur Ideas <a href="http://www.entrepreneurideas.biz">Entrepreneur Ideas</a>

<a href="http://www.battlestar-caprica.com">Battlestar Caprica</a>

<a href="http://www.50inchflatscreentv.net">50 Inch Flat Screen Tv</a>

>>  Aleksandra said on 09/16/10 20:20:39

Aleksandra <a href="http://www.entrepreneurideas.biz">Entrepreneur Ideas</a><br />
<a href="http://www.entrepreneurideas.biz">Entrepreneur Ideas</a><br />

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: