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