Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

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

I was relaxing the other day, browsing through some old golfs at shinh's golf site, when I noticed ySas' solution to the "add_some_brainf..._code" game called the getc function. I thought, "that's odd-looking Ruby code with all those $ characters in it", when it dawned on me that it was not Ruby code at all, but Perl! Perl has a getc function? Really? I'm deeply embarrassed to admit, despite having used Perl heavily for 10 years, I did not know that. After picking myself up off the floor, I realised I'd made an appalling oversight in that getc could shorten my previous best Roman Perl solution like so:

$\+=($n="1E@-"%9995)-$\%$n*2while IXCMVLD=~getc;print
53 strokes! What I find interesting here is that while is two strokes longer than for, and getc two strokes longer than <>, yet combining these two longer constructs produces a solution four strokes shorter than:
$\+=($n=IXCMVLD=~$_*"1E@-"%9995)-$\%$n*2for<>=~/./g;print

During the opening months of this competition, Perl led Ruby by 60 strokes to 73. At that stage, I thought it "impossible" for Ruby to ever catch Perl. To my great surprise, I whittled away at my Ruby solution until (to my dismay) it overtook my shortest Perl solution. After more than two years of play, the situation was reversed, with Ruby leading Perl by 53 to 58. Now I was sure that Perl had no chance of ever catching Ruby. As you might expect then, I'm delighted that the shortest known Perl and Ruby solutions are now tied at 53 strokes:

$\+=($n="1E@-"%9995)-$\%$n*2while IXCMVLD=~getc;print n=1;$.+=n/2-n%n=10**(494254%C/9)%4999while C=getc;p$.
And they both use the getc function. :-)

Update: a couple of Ruby equivalents of the Perl solution:

t=0;t+=(n=10**I%9995)-t%n*2while I="IXCMVLD"=~/#{getc.chr}/;p t t=0;t+=(n=10**I%9995)-t%n*2while I="IXCMVLD".index(getc);p t


In reply to Re^2: The golf course looks great, my swing feels good, I like my chances (Part I) by eyepopslikeamosquito
in thread The golf course looks great, my swing feels good, I like my chances (Part I) 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 meditating upon the Monastery: (8)
    As of 2014-08-01 00:38 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (256 votes), past polls