note
eyepopslikeamosquito
<P>
After applying the new terminating regex to Ruby via the following 175 stroker:
<CODE>
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"+$&
</CODE>
I could not restrain myself from trying to reduce it further.
Two eyesores that I found extremely annoying were:
<ul>
<li> The space between the <C>~/s/</C> and <C>until</C>.
<li> The <C>n=0;</C> initialization, which is not needed in Perl.
</ul>
Can anything be done about them?
To get rid of the wretched space, I tried reorganizing via:
<CODE>
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"+$&
</CODE>
Still a space before the <C>until</C> and still 175 strokes. Rats.
Chanting Eugene's <I>"can't possibly work, try it anyway"</I> mantra,
I changed <C>~/, 99\D+/</C> to <C>/, 99\D+/</C> and it worked!
Though it now emits a <I>"warning: regex literal in condition"</I> 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.
</P>
<P>
What about the <C>n=0;</C> initialization?
At this point, I remembered the [id://761053|Roman to Decimal challenge],
where I was able to avoid an initialization by hijacking the <C>$.</C>
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, <C>$.</C> is initialized to
the value four. So I scribbled this down during my lunchtime walk to
Neutral Bay today:
<CODE>
n=0;n+=1
4-$.-=1
</CODE>
Hmmm, well that's clearly one stroke less. But will it work?
Or will Ruby complain when the <C>$.</C> "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:
<CODE>
$_="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"+$&
</CODE>
</P>
<P>
Update: an alternative 173 using Ruby symbols:
<CODE>
$_="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"+$&
</CODE>
</P>
<P>
Update: Note that [id://973872|dmd compressed my 173 stroke solution above] to 168 by using Ruby compression ...
and -- as indicated at [id://1012012] -- it seems highly likely that Ruby golf maestro flagitious
used Ruby compression in his 173 stroke solution! ... which, after years of painstaking effort,
makes my uncompressed 173-stroker above my best ever Ruby golf performance.
</P>
903641
907242