This is a special case of
The Indirect Sort.
In the Indirect Sort, you have two arrays of items,
and you want to sort the second array into the order
that is defined by the first array.
(To get the two arrays, use
split // on the two numbers.)
So the indirect sort method says to use this:
@order = split //, $order;
@rearrangeme = split //, $rearrangeme;
@indices = sort { $order[$a] <=> $order[$b] } (0..$digits-1);
@answer = @rearrangeme[@indices];
quidity's solution above
is simpler, but
the Indirect Sort technique is like a recipe that you can
apply without thinking whenever you have to arrange one array
items into the order that is specified by a different array,
so it's worth remembering.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.