top bar
QuickTopic free message boards logo
Skip to Messages

TOPIC:

99 bottles and 515 languages

9
RupertSPerson was signed in when posted
05-14-2003
06:35 PM ET (US)
<code> ... </code> ... the most underappreciated HTML tags in cyberspace!
8
Eli the BeardedPerson was signed in when posted
05-14-2003
02:19 PM ET (US)
So I go and write one in vim, and then see they already have
vi and vim examples.

:map #i jO99 bottle of beer on the wall, 99 bottle of beer, take one down and pass it around, 99 bottle of beer.<esc>
:map #e o<cr>No more bottles of beer on the wall!<esc>k
:map #n #tyyp<C-x>w<C-x>w<C-x>#s#n
:map #s :.s/bottles/bottle/g<CR>
:map #t :.s/\<\([1-9][0-9]\<bar>[2-9]\) bottle\>/&s/g<CR>
:map g #e#i#n

Start it by typing 'g' on a blank line.
7
Zed LopezPerson was signed in when posted
05-14-2003
02:14 PM ET (US)
Oops... you're right. I actually did my testing with just 3 bottles of beer.

I played golf with this last night, implementing it a dozen times or so -- my best is 144 strokes.

The site has several perl implementations, which I missed the first time. One, the minimal, is 138, but omits the most interesting part -- getting the singular right on "1 bottle." The signature one is a pretty good obfuscatory implementation.
6
jleaderPerson was signed in when posted
05-14-2003
01:36 PM ET (US)
Zed, aren't you missing an anchoring ^ in your second and third regexes? Any string containing "1 bottles" is going to lose an 's' in the second regex, yielding lines like:

91 bottle of beer on the wall,

Then, a compensating error in the third regex will put the 's' back to give:

90 bottles of beer on the wall,

The regexes should look more like this:

s/\d+/$&-1/e; s/^(1 bottle)s/$1/; s/^(0 bottle)/$1s/;

Now _that_ feels better!
5
Zed LopezPerson was signed in when posted
05-14-2003
02:58 AM ET (US)
Hate the perl solution.

$_="99 bottles of beer";
$o=" on the wall";
do {
  print "$_$o,\n$_,\n";
  s/\d+/$&-1/e;s/(1 bottle)s/$1/;s/(0 bottle)/$1s/;
  print "Take one down, pass it around,\n$_$o.\n"
} until /^0/;


Ah, that feels better.
4
Creepy StevePerson was signed in when posted
05-13-2003
06:02 AM ET (US)
The BASIC version is still incorrect. I wrote them about this before.

It says:

10 REM Basic version of 99 bottles of beer
20 FOR X=100 TO 1 STEP -1
30 PRINT X;"Bottle(s) of beer on the wall,";X;"bottle(s) of beer"
40 PRINT "Take one down and pass it around,"
50 PRINT X-1;"bottle(s) of beer on the wall"
60 NEXT


It should be:
10 REM Basic version of 99 bottles of beer
20 FOR X=99 TO 1 STEP -1
30 PRINT X;"Bottle(s) of beer on the wall,";X;"bottle(s) of beer"
40 PRINT "Take one down and pass it around,"
50 PRINT X-1;"bottle(s) of beer on the wall"
60 NEXT

I don't have BASIC to run this as a test, but I'm sure I'm right. I ran it by a friend who codes in Visual BASIC and assures me that I'm right.

Hey, I took BASIC in college!
3
Raph LevienPerson was signed in when posted
05-13-2003
01:32 AM ET (US)
Wow, an obscure language I designed as a teenager is in there (Io). There's even an implementation:

http://www.guldheden.com/~sandin/amalthea.html

I'm impressed.
2
RupertSPerson was signed in when posted
05-12-2003
10:40 PM ET (US)
Heh! The site has been redesigned recently, and looks rather nice. The site has been around for ages, but I'd forgotten about it. Just for fun, I decided to have a go at contributing a rather esoteric example to the site this afternoon -- 99 bottles coded in HAL/S, a real time PL/I variant language used for flight control on the Space Shuttle. Code below, and language details at http://www.netcomuk.co.uk/~spaceuk/hals/hals.html

Proof that I need better things to do with my non working hours. Hey NASA, need an extra engineer? :-)


C 2003 RUPERT SCAMMELL / PUBLIC DOMAIN
C THIS PROGRAM WILL PRINT THE POPULAR FOLK SONG
C 99 BOTTLES OF BEER ON THE WALL IN THE HAL/S
C PROGRAMMING LANGUAGE, A REAL TIME FLIGHT CONTROL
C LANGUAGE PRIMARILY USED FOR FLIGHT CONTROL SOFTWARE ON
C US SPACE SHUTTLES.
                                                  
NINETY_NINE_BOTTLES:
PROGRAM;
        DECLARE NUM_BOTTLES INTEGER;
        DECLARE BBWALL CHAR(30);
        DECLARE BBEER CHAR(30);
        DECLARE TWDOWN CHAR(50);
        BBWALL = ' Bottles of Beer on the Wall';
        BBEER = ' Bottles of Beer.';
        TWDOWN = 'Take one down, and pass it around...';
                                                  
        DO NUM_BOTTLES = 99 TO 1 BY -1:
                WRITE(6) NUM_BOTTLES||BBWALL;
                WRITE(6) NUM_BOTTLES||BBEER;
                WRITE(6) TWDOWN;
                WRITE(6) NUM_BOTTLES - 1||BBWALL||'.';
        END;
        WRITE(6) 'NO MORE BOTTLES OF BEER ON THE WALL!';

CLOSE NINETY_NINE_BOTTLES;


[oops - fix song lyrics!]
[more bugs!]
Edited 05-13-2003 12:27 PM
1
giraffePerson was signed in when posted
05-12-2003
09:23 PM ET (US)
fantastic!
Upgrade to PRO

Upload pictures, personalize your board, and more!

Print | RSS Views: 347 (Unique: 266 ) / Subscribers: 1 | What's this?