in reply to Finding a LCS module on word level

I may be missing something, but isn't this kinda like (untested!):
sub lcs { my ($string, $find) = @_; my $l = length $find; while ( $l > 0 ) { my $pos = index( $string, $find ); if ( $pos > -1 ) { return ( $pos, $l ); } $l--; chop $find; } return; }

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^2: Finding a LCS module on word level
by ikegami (Patriarch) on May 09, 2008 at 02:52 UTC
    It fails for lcs('axb', 'cxd');
      Ah, so we have to examine the powerset of substrings and not just the stem. Ok, that's just a change to the loop. I think my point still stands, though.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
        dragonchild,
        I didn't review your logic other than to see you are using index. I am fairly certain that is a flawed approach since the OP is looking for the longest common substring based on words not characters.
        Have you ever seen the rain I have never seen the rain # should produce "seen the rain" not "ever seen the rain" because "eve +r" ne "never"

        Cheers - L~R