Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: Find the shortest word in the English Language with: a b c d e f

by mr_mischief (Monsignor)
on Jul 06, 2018 at 18:02 UTC ( #1218060=note: print w/replies, xml ) Need Help??


in reply to Re^3: Find the shortest word in the English Language with: a b c d e f
in thread Find the shortest word in the English Language with: a b c d e f

I'm not accustomed to needing to specify the argument within the code. It's not like it's a command-line flag. I count yours at 78.

while(<>){$a=a;$a++while/$a/i;push@{$_[y///c]},$_ if$a gt f}@_=map$_?@ +$_:(),@_

If you're to actually print out the shortest, make it 89. Still quite a bit shorter than mine.

while(<>){$a=a;$a++while/$a/i;push@{$_[y///c]},$_ if$a gt f}@_=map$_?@ +$_:(),@_;print$_[0]

Of course, looking closely only one of your loops needs to be of the 'while' variety. 87 (or 76 unconcerned about output).

for(<>){$a=a;$a++while/$a/i;push@{$_[y///c]},$_ if$a gt f}@_=map$_?@$_ +:(),@_;print$_[0]
for(<>){$a=a;$a++while/$a/i;push@{$_[y///c]},$_ if$a gt f}@_=map$_?@$_ +:(),@_

Replies are listed 'Best First'.
Re^5: Find the shortest word in the English Language with: a b c d e f
by Eily (Monsignor) on Jul 07, 2018 at 07:52 UTC
    I'm not accustomed to needing to specify the argument within the code

    Since the discussion started as a comparison against python, I wanted to play fair-ish and have code that actually does the same thing (technically, the same thing as the perl version in the OP). That's why I didn't include the glob version in the first place, or didn't print the result

    Of course, looking closely only one of your loops needs to be of the 'while' variety

    Nice catch! I'm far too used to using while for files to have seen this one :-).

Re^5: Find the shortest word in the English Language with: a b c d e f
by shmem (Chancellor) on Jul 10, 2018 at 16:58 UTC

    Two chars off if you put the constant first in the commaprison (good practice anyways :) and get rid of the 'if' statement modifier using '&&':

    for(<>){$a=a;$a++while/$a/i;f lt$a&&push@{$_[y///c]},$_}@_=map$_?@$_:( +),@_;print$_[0]

    Five chars of if you get rid of transforming @_ and grab directly what you want:

    for(<>){$a=a;$a++while/$a/i;f lt$a&&push@{$_[y///c]},$_}print+(map$_?@ +$_:(),@_)[0]

    82. I'm sure tybalt89 can do better, though.

    update: I wonder why biface isn't a verb proper, meaning treat someone with a biface. The shortest word would then be bifaced which seems fitting to me, huffman-coding anglo-saxonian history.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
      perl -e '/a/&/b/&/c/&/d/&/e/&/f/&&($a[99-y///c].=$_)for<>;print pop@a' + /usr/share/dict/words

      Outputs:

      boldface feedback
        boldface

        head -n1 /usr/share/dict/README; perl -e '/a/&/b/&/c/&/d/&/e/&/f/&&($a[99-y///c].=$_)for<>;print pop@a' /usr/share/dict/words

        On macOS High Sierra 10.13.4:
        
        #	@(#)README	8.1 (Berkeley) 6/5/93
        feedback
        


        STOP REINVENTING WHEELS ⚛ START BUILDING SPACE ROCKETS!CPAN 🐪

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1218060]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2020-09-29 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (144 votes). Check out past polls.

    Notices?