Voting

Category

real language

Bookmarking

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

Language B

(Ken Thompson's B, predecessor to C)

Date:08/21/06
Author:Pietro Gagliardi
URL:http://www.andlabs.com/
Comments:4
Info:http://cm.bell-labs.com/cm/cs/who/dmr/kbman.html
Score: (2.95 in 105 votes)
/* 99 Bottles of Beer
   B Version
   By Pietro Gagliardi
   Started and Completed August 21, 2006
   Try this if you can access a 1st edition Unix! :-) */

main()
{
    auto a;

    while (a >= 0) {
        printf("%d %s of beer on the wall!*n", a, (a == 0 ? "bottle" : "bottles"));
        printf("%d %s of beer,*n", a, (a == 0 ? "bottle" : "bottles"));
        printf("You take one down, pass it around,*n");
        if (a == 0) break;
        printf("%d bottles of beer on the wall!*n*n", --a);
    }

    printf("No more bottles of beer on the wall!*n");
}

Download Source | Write Comment

Alternative Versions

Comments

>>  Han ten Have said on 08/25/06 01:28:18

Han ten Have
I don't have a 1st edition Unix, nor any later 1, but...

DOES THIS WORK ?

It looks like "1 bottles" and "0 bottle" to me,
although it will "break" before it ever uses "0 bottle" !

And does "auto a" start at 99 ?
/* Is 99 snatched from within the comment ? :-) */

It would probably be better if this program would not be
completed within one day.

I found it when there were only 997 variations of
99-bottles-of-beer. Somehow Oliver Shade suddenly counted
1000 without any new additions. There must be a lot of
beer involved here...

But not in B : When the one-thousand celebrations reach
a high there is no replenishing by "going to the store" !

Nonetheless, congratulations with 1000, I like this site !


Han ten Have (Bidnija, Malta)


P.S. For a clear description of full 99-logic see the
dedicated intermediate language in my DEBUG version of 99.
It could be implemented with any Turing-complete language
although mine is not.

>>  Pietro Gagliardi said on 08/25/06 05:11:08

Pietro Gagliardi Sorry about forgetting the line a = 99;, which initializes the variable; my mistake. The correct code reads:

/* 99 Bottles of Beer
B Version
By Pietro Gagliardi
Started and Completed August 21, 2006
Try this if you can access a 1st edition Unix! :-) */

main()
{
auto a;
a = 99;

while (a >= 0) {
printf("%d %s of beer on the wall!*n", a, (a == 0 ? "bottle" : "bottles";));
printf("%d %s of beer,*n", a, (a == 0 ? "bottle" : "bottles";));
printf("You take one down, pass it around,*n";);
if (a == 0) break;
printf("%d bottles of beer on the wall!*n*n", --a);
}

printf("No more bottles of beer on the wall!*n";);
}

>>  Filipe said on 06/09/09 23:19:02

Filipe It's been almost thee years and I don't really know B, but if that's an arithmetic if then the first commenter was right: that code will print "1 bottles".

>>  ugg boots said on 09/07/10 11:42:41

ugg boots fashion ugg pink,ugg boots sale,ugg 5815,ugg 5825 "is getting "green".!!!
ugg boots sale ugg classic tall,ugg slippers,ugg boots uk
ugg boots tall,ugg boots,ugg boots uk,ugg boots sale,
ugg boots,ugg boots sale,ugg boots uk,UGG Handbags, UGG 5854 Classic Mini,UGG 1647 Tasmina,UGG 1688 Amelie Sandals,UGG 1759 Gypsy Sandal,
Ugg Women Elsey 5596,Ugg Womens Broome 5511,Ugg Tall Stripe Cable Knit 5822,UGG Womens Corinth 5756 Cocoa,Ugg Ultra Tall 5245,ugg boots,UGG Classic Tall 5815,UGG Classic Short 5825,UGG Classic Cardy 5819,UGG Bailey Button 5803,UGG Metallic Tall 5812,free shipping,sale online.!!!
Classical p90x,p90x workout,covers all the way of fitness methods.
We could enjoy best cheap cheap nike shoes sales online,about all kinds of nike air max,nike air max 90,nike shox.Run retailing and wholesale trade worldwidely for years,free shipping, super sale off retailing with 1 week delivery to your door.

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: