Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

After applying the new terminating regex to Ruby via the following 175 stroker:

n=0;~/s/ until/, 99\D+/=~$_="Take one down and pass it around, #{c=n+= +1," bottle#$& of beer"," on the wall"}. #{c}, %s%s. #$_"%c;puts$'+"Go to the store and buy some more"+$&
I could not restrain myself from trying to reduce it further. Two eyesores that I found extremely annoying were:
  • The space between the ~/s/ and until.
  • The n=0; initialization, which is not needed in Perl.
Can anything be done about them? To get rid of the wretched space, I tried reorganizing via:
n=0;$_="Take one down and pass it around, #{~/s/;c=n+=1," bottle#$& of + beer"," on the wall"}. #{c}, %s%s. #$_"%c until~/, 99\D+/;puts$'+"Go to the store and buy some more"+$&
Still a space before the until and still 175 strokes. Rats. Chanting Eugene's "can't possibly work, try it anyway" mantra, I changed ~/, 99\D+/ to /, 99\D+/ and it worked! Though it now emits a "warning: regex literal in condition" message to stderr, that does not matter to codegolf. Another stroke shaved. Not as I intended, but no matter. Only one more needed to catch flagitious.

What about the n=0; initialization? At this point, I remembered the Roman to Decimal challenge, where I was able to avoid an initialization by hijacking the $. variable. Indeed, if you want a numeric variable initialized to a known value, that is the only built-in variable Ruby makes available. Given my program is four lines in length, $. is initialized to the value four. So I scribbled this down during my lunchtime walk to Neutral Bay today:

n=0;n+=1 4-$.-=1
Hmmm, well that's clearly one stroke less. But will it work? Or will Ruby complain when the $. "line number" becomes negative? Nope, not a whimper about a negative line number. So, much to my surprise, I've now tied flagitious for the Ruby lead on 173 strokes:
$_="Take one down and pass it around, #{~/s/;c=4-$.-=1," bottle#$& of +beer"," on the wall"}. #{c}, %s%s. #$_"%c until/, 99\D+/;puts$'+"Go to the store and buy some more"+$&

Update: an alternative 173 using Ruby symbols:

$_="Take one down and pass it around, #{c=4-$.-=1," bottle#{c&&:s} of +beer"," on the wall"}. #{c}, %s%s. #$_"%c until/, 99\D+/;puts$'+"Go to the store and buy some more"+$&


In reply to Re^3: Drunk on golf: 99 Bottles of Beer by eyepopslikeamosquito
in thread Drunk on golf: 99 Bottles of Beer by eyepopslikeamosquito

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (5)
    As of 2014-04-19 18:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (483 votes), past polls