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

(Exact and complete lyrics)

Date:03/07/08
Author:Raphaël Bois
URL:n/a
Comments:4
Info:n/a
Score: (4.12 in 137 votes)
# 99 bottles of beer in Brainf*ck
# Copyright (C) 2008 Raphael Bois
# 1671 brainf*ck instructions.
# Published under GPL v2

Initialization
++    Counter for loop (a)
>+    unused
>++   Counter for loop (b)
>     Flag for 'no more'
>+    Flag for not 'no more'
>>>   (5) to (7) : temporary values
++++++++++[->+>+>++++++++++<<<]>>>    10 10 100 in (8) (9) (10)
>++++++++++   10 in (11)
[-
   >+++++           50  in (12)
   >++++++++++      100 in (13)
   >+++++++++++     110 in (14)
   >++++++++        80  in (15)
   >++++++++        80  in (16)
   >+++             30  in (17)
   >++++            40  in (18)
   >+               10  in (19)
   <<<<<<<<]
+
>-- +             48  '0'   plus 1 in (12)
>++ +             102 'f'   plus 1 in (13)
>+++++ +          115 's'   plus 1 in (14)
>-- +             78  'N'   plus 1 in (15)
>++++ +           84  'T'   plus 1 in (16)
>++ +             32  ' '   plus 1 in (17)
>++++ +           44  comma plus 1 in (18)
> +               10  LF    plus 1 in (19)

stuff for writing parts of the song
>+   select stuff
>+   select stuff
>+   write song part 3
>++  write song part 1
>+   write song part 2
>+   Flag for 'end of song'
>++  Flag for not 'end of song'

All bytes are at val plus 1
Go back to (7) with final initialization step (remove 1 to all bytes)
[-<]

<<<<<<< at (0)
[ loop (a)
-

>> at (2)
[ loop (b)

  >>>>>>>> at (10)
  [ start loop

    <<<<<<< at (3)
    [->[-]
      print '(N|n)o more'
      >>>>>>>>>>>.  '(N|n)'
      <----.        'o'
      >>>.          ' '
      <<<--.        'm'
      ++.           'o'
      +++.+         'r'
      <-.+          'e'
      <<+<<<<<<<<
    ]+> at (4)
    [-<[-]>>>>> at (9)
      prints number (using (9) and (10))
      [>>>+<<<<+<+<+>>>-]<<<[->>>+<<<]> at (6)
      [>>>>>>+<<<<<<-]>>>>>[[-]>.<]<<<<[>>>>>-<<<<<-]>> at (9)
      [<<+<+<+>>>>-]<<<<[->>>>+<<<<]> at (6)
      [>>>>>>+<<<<<<-]>>>>>>.<<<<<[>>>>>-<<<<<-] at (7)

      memorize in (11) if (10) not 1
      >>>[-<<<+<+>>>>]<<<<[->>>>+<<<<]>-[[-]>>>>+<<<<]<<< at (4)
    ]+

    >>>>>>>> at (12)
    print ' bottle(s) of beer'
    >>>>>.      ' '
    <<<<----.    'b'
    >----.       'o'
    +++++..-     'tt'
    <++++++++++. 'l'
    -------.     'e'
    <<[[-]>>>.<<<]>> 's' if (11)==1 ie if (10)!=1
    >>>>.        ' '
    <<<----.     'o'
    <+.          'f'
    >>>>.        ' '
    <<<<----.    'b'
    +++..+       'ee'
    >+++.+       'r'

    [>] at (20)

    +>+>[->+<<-<-
         print ' on the wall' DOT LF LF
         <<<.            ' '
         <<<----.        'o'
         -.              'n'
         >>>.            ' '
         <<<++++++.      't'
         <++.            'h'
         ---.            'e'
         >>>>.           ' '
         <<<+++.         'w'
         <----.          'a'
         +++++++++++..   'll'
         ------>----     reset to 'f' and 's'
         >---------- ---------- ---------- -- sets (15) to 'N'

         >>>++.--  DOT
         >..       LF LF
    >>>] at (22)

    >>>[->[-]<<<<<<<[<]<[-]>>[>]>>>>>]+ if end of song reset bottles counter
    >[-<[-] at (25)
      <<<< at (21)
      [->>[->+<<<<-
           print ' on the wall' COMMA ' '
           <<<.            ' '
           <<<----.        'o'
           -.              'n'
           >>>.            ' '
           <<<++++++.      't'
           <++.            'h'
           ---.            'e'
           >>>>.           ' '
           <<<+++.         'w'
           <----.          'a'
           +++++++++++..   'll'

           ------>----     reset (13) and (14) to 'f' and 's'
           >++++++++++ ++++++++++ ++++++++++ ++ sets (15) to 'n'

           >>>.            comma
           <.              ' '
      >>>>>>]<<]< at (20)

      [->>>>[-<<+< at (21)
             <<<++.--       DOT
             >.             LF

             [<]<<<<<<<< at (3)
             [->[-]<]+>  at (4)
             [-<[-]>
               >>>>>>>>>>>>.  'T'
               <<<-----.      'a'
               ++++++++++.    'k'
               ------.        'e'
               >>>>.          ' '
               <<<----.       'o'
               -.             'n'
               <.             'e'
               >>>>.          ' '
               <<<<-.         'd'
               >+.            'o'
               ++++++++.      'w'
               ---------.     'n'
               >>>.           ' '
               <<<<---.       'a'
               >.             'n'
               <+++.          'd'
               >>>>.          ' '
               <<<++.         'p'
               <---.          'a'
               >+++..         'ss'
               >>>.           ' '
               <<<<++++++++.  'i'
               >+.            't'
               >>>.           ' '
               <<<<--------.  'a'
               >--.           'r'
               ---.           'o'
               ++++++.        'u'
               -------.       'n'
               <+++.          'd'
               ++>+++++       reset (13) and (14) to 'f' and 's'
               >>>>.          comma
               <.             ' '

               [<]<<<<<<< at (4)
             ]+

            >>>>>> at (10)
            decrements values
            -<<<+>>[<<[-]<+<+>>>>-]<<<<[>-<[-]]>[->>>+<<<]>[->->+++++++++<<]>>> at (10)

         >>[>]>>>>] at (24)
      <<<<] at (20)

    >>>>>>]+ at (26)

    <<<<<<<[<]< at (10)
  ]
  +<+
  <<<<<<+< at (2)
  -
]

print 'Go to the store and buy some more' comma ' '

  >>>>>>>>>>[>]>>>>> at (25)
  [->[-]<]+> at (26)
  [-<[-]
    <<<<<<<<< at (16)
    -------------.   'G'
    <<----.          'o'
    >>>.             ' '
    <<<+++++.        't'
    -----.           'o'
    >>>.             ' '
    <<<+++++.        't'
    <++.             'h'
    ---.             'e'
    >>>>.            ' '
    <<<-.            's'
    +.               't'
    -----.           'o'
    +++.             'r'
    <.               'e'
    >>>>.            ' '
    <<<<----.        'a'
    >----.           'n'
    <+++.            'd'
    >>>>.            ' '
    <<<<--.          'b'
    >+++++++.        'u'
    ++++.            'y'
    >>>.             ' '
    <<<------.       's'
    ----.            'o'
    --.              'm'
    <+++.            'e'
    >>>>.            ' '
    <<<.             'm'
    ++.              'o'
    +++.+            'r'
    <.+              'e'
    >>>>>.           coma
    <.               ' '
    >>>>>>>>>
  ]+

  Initialize last loop to print final '99 bottles of beer on the wall' DOT
  <[-]+<[-]<[-]<[-]+<<< at (19)
  [<]<[-]<[-]<[-]<[-] at (7)
  ++++++++++[->+>+>++++++++++<<<]>->->-
  <<<<<<[-]+<[-]<+<< at (0)
]

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
bottle shapedMichal Wojciech Tarnowski11/13/100
original versionAndrew Paczkowski05/30/0529
lean and meanAki Rossi06/29/074
slightly improved versionMark Hurd07/01/051

Comments

>>  Mark Watson said on 04/23/08 04:59:11

Mark Watson Single greatest name for a programming language I have ever seen.

And the best part - this stuff really does F*CK with your brain!

>>  Thorsten Glaser said on 07/01/10 23:05:20

Thorsten Glaser

>>  Thorsten Glaser said on 07/01/10 23:08:45

Thorsten Glaser Ouch, this submission form hurts. Well, look here:

https://www.mirbsd.org/cvs.cgi/contrib/hosted/tg/hellow/bottles.bf.diff?r1=1.1;r2=1.2

>>  barrym said on 09/19/10 23:40:47

barrym @Thorsten: I found a useful trick for posting code in the comment section without
losing the formatting. Just put a [ c o d e ] (without the spaces and on its own
line) at the beginning and a [ / c o d e ] at the end, and your code sample stands
out nicely with most of its formatting preserved. :)

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: