Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Competition fuels obsession over Perl [golf]

by educated_foo (Vicar)
on Feb 19, 2004 at 03:34 UTC ( #330130=note: print w/ replies, xml ) Need Help??


in reply to Competition fuels obsession over Perl

Can't help myself. 74

-aln $$_=()=/[aeiou]/gi for@F;print"$$_ $_"for sort{$$b<=>$$a||$a cmp$ +b}@F


Comment on Re: Competition fuels obsession over Perl [golf]
Download Code
Replies are listed 'Best First'.
Re: Re: Competition fuels obsession over Perl [golf]
by eyepopslikeamosquito (Chancellor) on Feb 19, 2004 at 08:46 UTC

    3 strokes sh?aved.

    #!perl -aln $$_=y/aAeEiIoOuU//for@F;print"$$_ $_"for sort{$$b-$$a||$a cmp$b}@F

    Using a G-R transform (and assuming less than 9 vowels per word) saves 8 more.

    #!perl -an print+map{/./;9-$&.$'}sort map{9- y/aAeEiIoOuU//." $_\n"}@F

    /-\

      Oh, man I'm rusty. Here are a few minor tweaks. For the full version, one less:
      $$_=lc=~y/aeiou//for@F;print"$$_ $_"for sort{$$b-$$a||$a cmp$b}@F
      For the "less than ten vowels" version, you can also lose one by getting rid of that space after the "map{9-".

      Finally, if they meant increasing order of vowel count and less than nine vowels, then we can do much better ;)

      -an print sort map y/aAeEiIoOuU//." $_\n",@F

        For the "less than ten vowels" version, you can also lose one by getting rid of that space after the "map{9-".

        Alas, Perl complains with Unrecognized file test: -y if you try that. However, using your lc trick saves two more strokes:

        print+map{/./;9-$&.$'}sort map{9-lc=~y/aeiou//." $_\n"}@F

        You could allow up to 90 vowels (at the cost of 3 strokes) by changing 9 to 99 and . to ..

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2015-07-28 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls