Do you know where your variables are? | |
PerlMonks |
Re^3: Drunk on golf: 99 Bottles of Beerby eyepopslikeamosquito (Archbishop) |
on Jun 03, 2011 at 12:48 UTC ( [id://907967]=note: print w/replies, xml ) | Need Help?? |
After applying the new terminating regex to Ruby via the following 175 stroker: I could not restrain myself from trying to reduce it further. Two eyesores that I found extremely annoying were:
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: 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:
Update: an alternative 173 using Ruby symbols:
Update: Note that dmd compressed my 173 stroke solution above to 168 by using Ruby compression ... and -- as indicated at Re^3: Compression in Golf: Part III -- 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.
In Section
Meditations
|
|