I visited the Rosetta Code, for solution to a problem in a language, which both don't matter here; then checked Perl solution there; then, out of idle curiosity, as it's usual with time wasting e.g. browsing dictionaries, clicked for one more task; and -- I swear (and don't know what in its title attracted me)-- at exactly the 3d task I found a Perl solution:

https://rosettacode.org/wiki/Change_e_letters_to_i_in_words#Perl

Out of ALL contestants, the task was misread to include 5-letter words, and even then, the algorithm is broken as it doesn't contain e.g. "crises crisis" pair, etc. So sad :-(. Village idiot, our Perl, no less. No, I don't have editing rights there, nor did I find in page's history how/when it was added.

However, I've been surprised to find it hard and not obvious (to me), how to match the solution's speed/memory. Presumably, if corrected they'd stay the same or close. My initial attempts with e.g. grep/map/split/regexes or what not -- they all were worse.

Finally, here's my solution (under Strawberry):

use strict; use warnings; sub memory { qx( tasklist /nh /fi "PID eq $$" ) =~ m[(\S+ K)$] } use Time::HiRes 'time'; my $t = time; my ( @a, %h ); open my $fh, '<:raw', 'unixdict.txt' or die; while ( <$fh> ) { next unless length > 6; chomp; ( -1 != index $_, 'e' ) ? ( push @a, $_ ) : ( -1 != index $_, 'i' ) ? ( $h{ $_ } = 1 ) : 1 } close $fh; my ( $s, $i ) = ''; exists $h{ $i = tr/e/i/r } and $s .= sprintf "%30s %s\n", $_, $i for @a; print time - $t, "\n"; print memory, "\n"; print $s;

It's on average "0.018 s, 10,100 K" vs "0.033 s, 11,100 K" of similarly modified (but still unfixed) original. Not that "performance" matters for the task, how ever ridiculous this achievement is.


In reply to Perl at Rosetta Code, with one particular example by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.