Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Golf: Arbitrary Alphabetical Sorting

by ChemBoy (Priest)
on May 09, 2001 at 20:42 UTC ( #79151=note: print w/ replies, xml ) Need Help??


in reply to Golf: Arbitrary Alphabetical Sorting

I got a head start on this one, since I gave a recursive solution in the original thread. But I've never golfed before, so this is likely to go down in flames quickly... I believe it scores 110 as is (somewhat golfed, but probably not optimally).

sub o { $q=join'',@{$_[0]}; sort {$i=0; {index($q,substr($a,$i,1))<=>index($q,substr($b,$i,1))or($i++,redo)}}@ +{$_[1]} }

Update: Oof... difficulties is a nice way of putting it. A conditional statement fixes that, probably more cleanly than checking the string length repeatedly. Up to 125, I think--but then, I've already been clobbered.

sub o { $q=join'',@{$_[0]}; sort {$a cmp$b?do{$i=0;{index($q,substr($a,$i,1))<=>index($q,substr($b +,$i,1))or($i++,redo)}}:0 }@{$_[1]} }



If God had meant us to fly, he would *never* have give us the railroads.
    --Michael Flanders


Comment on Re: Golf: Arbitrary Alphabetical Sorting
Select or Download Code
Replies are listed 'Best First'.
Re: Re: Golf: Arbitrary Alphabetical Sorting
by MeowChow (Vicar) on May 09, 2001 at 20:57 UTC
    This is nice, but it has ahhh... difficulties with repeated words in the list to be sorted.
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2015-07-29 06:07 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 (260 votes), past polls