[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] words words words



What would be a fun (short | elegant | fast) way, given two files
with nine- and three-letter words one per line, respectively, of
listing only those nines which are the concatenation of three
threes?

Anyone who wants to go so far as to do relative benchmarks
should use the three- and nine-letter words from
<http://www.geocities.com/TimesSquare/Castle/5057/TWL98.zip>

Here's the shortest I have (modulo whitespace):

#!/usr/local/bin/perl -nw
BEGIN {
    open T, "threes";
    chomp (@t = <T>);
    $re = join '|', @t;
}
/^(?:$re)*$/o && print;

and this is my fastest:

#!/usr/local/bin/perl -w
open T, "threes"; chomp(@t = <T>);
undef $/;
open N, "nines" ;       $n = <N>;
for(@t) {
    $n =~ s/$_(?=(?:...)*\n)/\L$_/g;
}
$n =~ s/^[a-z]*[A-Z][A-Za-z]+\n//gm;
print $n;


  Steven Alexander
  stevena@teleport.com
  <http://www.teleport.com/~stevena/>

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe