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

Bottle Golf

by inman (Curate)
on Jun 10, 2004 at 21:07 UTC ( #363199=perlquestion: print w/ replies, xml ) Need Help??
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?

Comment on Bottle Golf
Download Code
Re: Bottle Golf
by shemp (Deacon) on Jun 10, 2004 at 21: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 21: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 21: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
Node Status?
node history
Node Type: perlquestion [id://363199]
Approved by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2014-08-30 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls