http://qs321.pair.com?node_id=259291

gryphon has asked for the wisdom of the Perl Monks concerning the following question:

Greetings fellow monks,

I just finished an interesting coding problem for work. We have an online test-taking & grading system, and while doing some updates for it, I needed an algorithm that renders a numeric sequence in order by letter, regardless of the numbers within the sequence. For example:

5, 100, 2, 8, 40 ...becomes... B, E, A, C, D

After some tinkering, I came up with the following:

my @original_array = qw(5, 100, 2, 8, 40); my @sequence; my @ordered = sort @original_array; for (my $y = 0; $y < scalar @ordered; $y++) { for (my $x = 0; $x < scalar @ordered; $x++) { push @sequence, $x + 1 if ($ordered[$x] == $original_array[scalar @sequence]); } } my @letter_sequence = map { local $_ = $_; tr/1-9/a-h/; $_ } @sequence +;

I was wondering if any of you all had encountered such a problem in the past and if so if you have any code for it that's shorter than what I've posted. The above works, as far as I can tell, but I have a sneeking suspicion that there's a much better way to write it. (Oh, and the @original_array will never be bigger than 9 elements.) Thanks.

gryphon
code('Perl') || die;