in reply to Golfing on a quiet Friday afternoon...

Some evolution for you:
#2345678901234567890123 print((stat pop)[7],$/) # 23 print+(stat pop)[7],$/ # 22 print+(-s pop),$/ # 17 print-s pop,$/ # 14
Ta da. 14.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re^2: Golfing on a quiet Friday afternoon...
by particle (Vicar) on Jul 27, 2002 at 00:42 UTC
    you missed one...

    #23456789012 die-s pop,$/

    ~Particle *accelerates*

Re: Re: Golfing on a quiet Friday afternoon...
by BrowserUk (Patriarch) on Jul 26, 2002 at 21:21 UTC

    I'm very new to golf and don't know the ground rules and was amazed by hans_moleman's solution and simply blown away by japhy's evolution, but.... (/me hear's the groans)...trying japhy's final answer on my win32 (that has -w permenantly enabled) system I got:

    C:\test>185653 185653.pl 16Use of uninitialized value in print at C:\test\185653.pl line 1. C:\test>

    Ignoring the warning which I could turn off, I noticed that it reports its own length (under win32 etc. etc) as 16!

    So, I played and came up with this, which (on my Wi...) does a little better and (visually at least :) complies with the 'rules'

    (I see a newline after the number :),

    and beats japhy's by 3!...and runs with -w and no errors!

    C:\test>185649 185649.pl 13 C:\test>

    And the code

    C:\test>type 185649.pl print-s pop C:\test>

    As an aside, in a unicode world, maybe the requirements should have been "number of bytes"?

      Ahh, certainly this is cheating BrowserUk {grin}.

      The version of emulated DOS on your Win32 system always places new command prompt on a separate line by itself. So, even if your perl script prints just '13' without a terminating '\n', DOS would do the job for you.

      However, for a Unix system I can't see how one could go shorter than just:
      #12345678901234 print-s pop,$/
      Which is 14 characters.

      Surely, had japhy considered writing his golf for DOS, then the ',$/' part would be dropped thereby reducing the golf even further by 3 characters as you've pointed out ;-)

      Update: To clarify, the word 'cheating' should be considered a sarcasm ;^). I didn't mean to sound offending. I very much respect BrowserUk's comment and have nothing against him pointing out the intimate features of perl running on various non *nix systems. I simply felt it would be worthwhile to also direct your attention to the minor difference in running the golf piece on Win32 and Unix systems.

      _____________________
      # Under Construction
        $ echo -n 'print-s pop,$/' > golf $ perl golf golf 14

        As japhy didn't specify a newline at the end, I assume he didn't want one. :-)

        -sauoq
        "My two cents aren't worth a dime.";
        

        Cheating? Possibly, except is

        Fully utilizing implied and default behaviours....

        One possibly definition of the word perlish?

        If so, does this desirability stop at Perl's front (or back) door? :^p


        On a slightly serious note, if you run japhy's mini masterpiece on itself on a *nix box, what does it report its own length to be? 14|15|16??

        I assume this will depend on whether the editor used to create the file automatically terminates the last (only) line, and how it is terminated?

Re: Re: Golfing on a quiet Friday afternoon...
by hans_moleman (Beadle) on Jul 26, 2002 at 20:56 UTC

    Thanks! very enlightening.