Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1

by johngg (Canon)
on Feb 05, 2019 at 14:33 UTC ( #1229410=note: print w/replies, xml ) Need Help??


in reply to Fastest way to sort a list of integers into 0,1,2,3,-3,-2,-1

A GRT on packed negativity indicator and value seems to work.

use 5.026; use warnings; say for map { unpack q{xl>}, $_; } sort map { my $neg = $_ < 0 ? 1 : 0; pack q{Cl>}, $neg, $_; } -4 .. 4;

The output.

0 1 2 3 4 -4 -3 -2 -1

I hope this is useful.

Update: I just noticed that Tux posted exactly the same method while I was posting this.

Update 2: Ah! Not quite the same, negativity indicator not required apparently.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (None)
    As of 2021-10-21 01:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My first memorable Perl project was:







      Results (82 votes). Check out past polls.

      Notices?