Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: 99 bottles, 2 lines

by jepri (Parson)
on Nov 28, 2000 at 13:40 UTC ( #43638=note: print w/replies, xml ) Need Help??

in reply to 99 bottles, 2 lines

You are a most remarkable programmer, chipmunk. I just spent four and a half hours working on this one instead of my essay and still didn't get anywhere. Here's my best:

foreach(1..99){$b="\n$_ bottle@{[$_!=1&&s=>]} of beer";push@a,",\nTake + one down, pass it round,$d@{$d=$b.' on the wall'}\n",$d.$b};print re +verse@a;

but the output isn't as nice as yours.

I had this great idea using quines and self-modifying code, but I was beaten by s///. The idea was to find every number in the program and decrement it by one with s/\d{2}/$1--/g but $1 is read only so I couldn't (my lesson for today). Oh well. The following code actually works.
Update: I don't know if it's just my browser but the second line isn't displaying correctly. It should be $b=99;$c=$b-1;. But it doesn't break to badly if $c gets mangled.

seek DATA, 38,0; + $_=join("",<DATA>); + $b=99;$c=$b-1; + $b/$b; + print "\n\n $b on the wall, $b. Take one down, pass it around, $c on +the wall." ; + s/$b/$b-1/e; + s/ (\$.)/$1 bottles of beer/g; + eval;__DATA__ +

I didn't believe in evil until I dated it.

Replies are listed 'Best First'.
(tye)Re: 99 bottles, 2 lines
by tye (Sage) on Nov 28, 2000 at 22:03 UTC


    Can't you just use:

    except that this will fail when you get down to 1 digit.

            - tye (but my friends call me "Tye")
Re: 99 bottles, 2 lines
by o(o_o)o (Scribe) on Jan 08, 2002 at 06:46 UTC
    Hey, i'm new to posting on here, and am trying to work on loadsa things to get myself better at programming in perl... and this one i thought looked cool... so i gave it a try, and nicked a bit of code from chipmunk's code and made my own... it's only 1 line... but one hell of a line... only 1 semicolon in sight! :-) i thought the horrible lot of numbers i put in the qw() could be done a better way, but i was trying to get it done in just the one line, so i gave up trying to think of a way to do it. but this is what i have.
    map { print "$_ bottle@{[$_!=1&&s=>]} of beer on the wall, $_ bottle@{ +[$_!=1&&s=>]} of beer. Take 1 down, pass it around, ".($_-1)." bottl +e@{[$_-1!=1&&s=>]} of beer on the wall.\n" } reverse 1..99;
    Update: the long line has been decreased thanks to blakem! now it's one line that actually looks pretty sweet! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    i would slit my wrists for you
      How about:
      my @a = reverse 1..99;
      you can probably just inline reverse 1..99 since I don't see you actually using @a anywhere....


        yeah! cool... thanks! i'm new to posting and am well happy someone gave me a helpfull reply! :-) thanks for makin the line smaller. i wont post the complete code coz people can just read this post to get it. ;) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        i would slit my wrists for you

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://43638]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2017-12-17 16:29 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (464 votes). Check out past polls.