in reply to Render numeric sequence as array of letters

I assume you want B E D A C as output, since B E A C D corresponds with 100 40 5 2 8. I'd use something similar to a Schwartzian Transfer:
my @original = qw /5 100 2 8 40/; my $s = "A"; my @sorted = map {$_ -> [1]} sort {$b -> [0] <=> $a -> [0]} map {[$_ => $s ++]} @original;

Abigail

Replies are listed 'Best First'.
Re: Re: Render numeric sequence as array of letters
by Util (Priest) on May 20, 2003 at 02:34 UTC

    I took the same approach, with the same assumption, and then realized that "ordered rank" was the objective.

    # Tested code; outputs: # B E A C D my @original = (5, 100, 2, 8, 40); my $s = 'A'; my $n = 1; my @sorted = map { $_->[2] } sort { $a->[1] <=> $b->[1] } map { [ @$_, $s++ ] } sort { $a->[0] <=> $b->[0] } map { [ $_, $n++ ] } @original; print "@sorted\n";