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:3
Info:http://cm.bell-labs.com/cm/cs/who/dmr/kbman.html
Score: (2.98 in 110 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".

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: