Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: (Golf) Keysort

by japhy (Canon)
on Feb 14, 2002 at 15:13 UTC ( #145460=note: print w/replies, xml ) Need Help??

in reply to (Golf) Keysort

Update 2: demerphq reminded me that his code returns the list. My code has been updated to do so, and comes in at 106:
# this is LEXICAL sorting #2345678901234567890123456789012345678901234567890123 sub JAPHY { sort{(*-,*+)=map[/^\s*(0|-?[1-9]\d{0,8})(.*)$/],$a,$b ;@-?@+?$-[0]-$+[0]||$-[1]cmp$+[1]:-1:@+?1:$a cmp$b}@_ }

Update: new code under 100, at 98... oh, notice how I'm leaving that space in between $a and cmp? If it's legal for me to put a newline there and not have it count, let me know.
#234567890123456789012345678901234567890123456789 sub JAPHY { (*-,*+)=map[/^\s*(0|-?[1-9]\d{0,8})(.*)$/],$a,$b; @-?@+?$-[0]-$+[0]||$-[1]cmp$+[1]:-1:@+?1:$a cmp$b }

Here's my sorting function, with a healthy count of 107:
#2345678901234567890123456789012345678901234567890123456 sub JAPHY { my($A,$B)=map[/^\s*(0|-?[1-9]\d{0,8})(.*)$/],$a,$b; @$A?@$B?$$A[0]-$$B[0]||$$A[1]cmp$$B[1]:-1:@$B?1:$a cmp$b }

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2022-01-23 08:35 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (63 votes). Check out past polls.