here is something small you might like to try if
halley's hash above proves too chunky for your ZX81.
the following will deposit the sorted subset
in @uS; the memory consumued will be of the
order of the size of elements in the unsorted
list. so it will be kind to machines with less RAM.
if the unsorted list is short, the fact that the only a few
grep's will be employed will make the solution
reasonable in time too.
my @S=("tilly","zaxo","sauog","enlil","castaway","wufnik");
my @U = ("castaway","zaxo","wufnik","enlil");
my %uS = map { $tmp = $_; $tmp => grep { $S[$_] =~ /^$tmp$/ } (0..$#S)
+ } @U;
@uS = sort { $uS{$a} <=> $uS{$b} } @U;
print join "\n", @uS;
which produces
zaxo
enlil
castaway
wufnik
from the unsorted list above.
it freely admit it won't always be the fastest solution, but it will be kind, at least to those who like map & grep.
...wufnik
-- in the world of the mules there are no rules --
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.