Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Bottle Golf

by inman (Curate)
on Jun 10, 2004 at 17:07 UTC ( [id://363199]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

inman has asked for the wisdom of the Perl Monks concerning the following question:

Probably done before. Generate the rhyme '10 green bottles...'
#! /usr/bin/perl -w foreach (reverse 1..10){ sub wall {$a=$_-1?'s':'';"$_ green bottle$a, standing on a wall\n"} print wall($_)x2, "and if 1 green bottle should accidentally fall\nthere'll be ", wall(--$_),"\n"}
Any other methods?

Replies are listed 'Best First'.
Re: Bottle Golf
by shemp (Deacon) on Jun 10, 2004 at 17:24 UTC
    #!/usr/bin/perl -w print join "\n", map { "and if 1 green bottle should accidentally fall +\n" ."there'll be " . ($_-1) . " green bottle" .plural($_) . ", standing on a wall\n" } (reverse 1..10); sub plural {return $_-1?'s':'';}
    whitespace added for clarity
Re: Bottle Golf
by shemp (Deacon) on Jun 10, 2004 at 17:32 UTC
    whoops, i guess my first attempt was a little off. Also, bottle should be pluralized except when there is 1 bottle left. Even zero bottles is plural.

    played a little more, here something better, without a sub
    print join "\n", map { "and if 1 green bottle should accidentally fall +\n" ."there'll be " . ($_-1) . " green bottle" .($_!=2?'s':'') . ", standing on a wall\n" } (reverse 1..10);

    (hopefully correct)
      This may be a bit off topic, but could people let me know why i got voted down for this post?
      Im thoroughly perplexed!
        There are any number of reasons that people downvote, ranging from thinking your post was overrated to XP whoring to retaliation for somebody doing it to them. If you don't see a problem with your post and they can't be bothered to point it out, don't worry about it.

        We're not really tightening our belts, it just feels that way because we're getting fatter.
Re: Bottle Golf
by Enlil (Parson) on Jun 10, 2004 at 17:44 UTC
      IIRC, the shortest known Perl solution to this problem was uncorked by Ton Hospel and Mtv Europe and, oddly, is documented in the 99 Bottles of Beer section of Acme::EyeDrops documentation.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://363199]
Approved by grinder
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.