Beauty of 99 Bottles of Beer in Perl

Perl is well known for allowing a software developer to express the solution in more than one way. And it can be harnessed to be as creative or cryptic as one likes to be. Here is one example I saw sometime back on http://99-bottles-of-beer.net/language-perl-737.html

Run the program as:

#!/usr/local/bin/perl


''=~( '(?{' .('`' |'%') .('[' ^'-')
.('`' |'!') .('`' |',') .'"'. '\\$'
.'==' .('[' ^'+') .('`' |'/') .('['
^'+') .'||' .(';' &'=') .(';' &'=')
.';-' .'-'. '\\$' .'=;' .('[' ^'(')
.('[' ^'.') .('`' |'"') .('!' ^'+')
.'_\\{' .'(\\$' .';=('. '\\$=|' ."\|".( '`'^'.'
).(('`')| '/').').' .'\\"'.+( '{'^'['). ('`'|'"') .('`'|'/'
).('['^'/') .('['^'/'). ('`'|',').( '`'|('%')). '\\".\\"'.( '['^('(')).
'\\"'.('['^ '#').'!!--' .'\\$=.\\"' .('{'^'['). ('`'|'/').( '`'|"\&").(
'{'^"\[").( '`'|"\"").( '`'|"\%").( '`'|"\%").( '['^(')')). '\\").\\"'.
('{'^'[').( '`'|"\/").( '`'|"\.").( '{'^"\[").( '['^"\/").( '`'|"\(").(
'`'|"\%").( '{'^"\[").( '['^"\,").( '`'|"\!").( '`'|"\,").( '`'|(',')).
'\\"\\}'.+( '['^"\+").( '['^"\)").( '`'|"\)").( '`'|"\.").( '['^('/')).
'+_,\\",'.( '{'^('[')). ('\\$;!').( '!'^"\+").( '{'^"\/").( '`'|"\!").(
'`'|"\+").( '`'|"\%").( '{'^"\[").( '`'|"\/").( '`'|"\.").( '`'|"\%").(
'{'^"\[").( '`'|"\$").( '`'|"\/").( '['^"\,").( '`'|('.')). ','.(('{')^
'[').("\["^ '+').("\`"| '!').("\["^ '(').("\["^ '(').("\{"^ '[').("\`"|
')').("\["^ '/').("\{"^ '[').("\`"| '!').("\["^ ')').("\`"| '/').("\["^
'.').("\`"| '.').("\`"| '$')."\,".( '!'^('+')). '\\",_,\\"' .'!'.("\!"^
'+').("\!"^ '+').'\\"'. ('['^',').( '`'|"\(").( '`'|"\)").( '`'|"\,").(
'`'|('%')). '++\\$="})' );$:=('.')^ '~';$~='@'| '(';$^=')'^ '[';$/='`';

It produces output like:

99 bottles of beer on the wall, 99 bottles of beer!
Take one down, pass it around,
98 bottles of beer on the wall!

98 bottles of beer on the wall, 98 bottles of beer!
Take one down, pass it around,
97 bottles of beer on the wall!

97 bottles of beer on the wall, 97 bottles of beer!

It is a beauty!


Another one in Perl ( http://99-bottles-of-beer.net/language-perl-658.html )

#!/usr/local/bin/perl
# Copyright 2001 Christopher J. Carlson
# All Rights Reserved

$a=
"cpuu
\bmft p
\bg cff
\bs";$b
="po ui
\bf xbm
\bm";$c="
Ypv ublf p
\bof epxo qb
\btt ju bspvoe";
$a =~ s/\n//;$a =~
s/\s+/ /g; $b =~
s/\n// ; $b =~
s/\s+/ /g;$c =~
s/\n// ; $c =~
s/\s+/ /g;$a =~
y/b-z/a-z/;$b =~
tr/b-z/a-z/;$c =~
tr/b-z/a-z/ ; for(
$d=100;$d>0;$d--){
print"$d $a $b $d"
;print" $a,\n$c, "
;print($d-1);print
" $a $b.\n";} $x =
"cjc"; $y="dobbz";
$z="com";print"\n"
;print "- $x\@$y."
;print"$z \n\n";

If you write it in more readable format, it would be

$a = "cpuu \bmft p \bg cff \bs";
$b = "po ui \bf xbm \bm";
$c = "Ypv ublf p \bof epxo qb \btt ju bspvoe";

$a =~ s/\n//;
$a =~ s/\s+/ /g;
$b =~ s/\n// ;
$b =~ s/\s+/ /g;
$c =~ s/\n// ;
$c =~ s/\s+/ /g;

$a =~ y/b-z/a-z/;
$b =~ tr/b-z/a-z/;
$c =~ tr/b-z/a-z/;
for( $d=100;$d>0;$d--) {
print"$d $a $b $d";
print" $a,\n$c, ";
print($d-1);
print " $a $b.\n";
}
$x = "cjc";
$y="dobbz";
$z="com";
print"\n";
print "- $x\@$y.";
print"$z \n\n";

It is a very simple program and all that is needed to produced the required output is done in “for” loop. All the substitutes (6 lines of code “s//;” is redundant and seem to be added to make a bottle shaped code. First 3 lines of code ($a, $b, $c) are simply a ASCII next letter of the original lines, meaning, “b” written as “c”, “t” as “u” and then translated back to original lines through “y/” and “tr/” Perl functions. $x,$y,$z are author email address.


A version in Python ( http://99-bottles-of-beer.net/language-python-808.html )

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
"""
99 Bottles of Beer (by Gerold Penz)
Python can be simple, too 🙂
"""

for quant in range(99, 0, -1):
if quant > 1:
print quant, "bottles of beer on the wall,", quant, "bottles of beer."
if quant > 2:
suffix = str(quant - 1) + " bottles of beer on the wall."
else:
suffix = "1 bottle of beer on the wall."
elif quant == 1:
print "1 bottle of beer on the wall, 1 bottle of beer."
suffix = "no more beer on the wall!"
print "Take one down, pass it around,", suffix
print "--"

Python code is pretty straight forward and self explainatory.


One of the simplest one – just grab the lyrics from the website 🙂
( http://99-bottles-of-beer.net/language-python-931.html )

#!/usr/local/bin/python
'''A more interesting way to get the lyrics to "99 Bottles of Beer on the Wall", in Python. Is this considered cheating?'''

import re, urllib
print re.sub('

', '', re.sub('
|

|
|
','\n', re.sub('No', '\nNo',
urllib.URLopener().open('http://www.99-bottles-of-beer.net/lyrics.html').read()[3516:16297])))



Hope you enjoyed it.
Shiva

Best of Google homepage logos over the years

Google modifies their home page by including birthdays of some major personalities around the world or major events. Here are some of the best, unique and presented in more than one country. The list below is not any particular order.

2009.05.20 – Charles Darwin Birthday

2009.11.13 – Water on Moon found

2009.10.02 – Mahatma Gandhi

1998.10.29 – Google Beta

1998.08.30 – Burning Man (One of the first of Google’s modified logos!)

2006.01.04 – Louis Braille’s Birthday

2008.05.16 – Laser Invention

2009.10.07 – Barcode Invention

2003.03.14 – Einstein’s Birthday

2006.02.11 – Olympics Snowboarding

2007.04.22 – Earth Day

2005.04.15 – Leonardo Da Vinci Birthday

2008.11.04 – US Election Day

2009.05.20 – Darwinius Masillae

2009.01.28 – Jackson Pollock Birthday

2002.05.20 through 24 – Dilbert Comics

 

2005.03.30 – Van Gogh’s Birthday

2006.12.12 – Edvard Munch Birthday

2008.06.06 – Diego Velazquez’s Birthday

2007.04.01 – April Fool Day   — (TiSP)

2009.02.12 – Samuel Morse Birthday

2004.02.03 – Gaston Julia’s Birthday

Fractals 

2009.10.29 – Asterix Comic’s 50th Anniversary

2008.01.28 – 50th Annivesary of the LEGO Brick

2009.10.31 – Happy Halloween

2008.01.01 – 25 Years of TCP/IP protocol