in reply to longest common substring (with needed tweaks)
output will be$_ = <DATA>; $_ = $` if /$/; @a = split //, $_; for $i (0 .. $#a){ $e = $a[$i]; $hash{$e} = 1; for $y ($i+1 .. $#a){ $e .= $a[$y]; $hash{$e} = 1; } } while(<DATA>){ $_ = $` if /$/; @a = split //, $_; %thash = (); for $i (0 .. $#a){ $e = $a[$i]; $thash{$e} = 1 if defined $hash{$e}; for $y ($i+1 .. $#a){ $e .= $a[$y]; $thash{$e} = 1 if defined $hash{$e}; } } foreach $key (keys %hash){ $hash{$key}++ if defined $thash{$key}; } } $max = ''; foreach $key (keys %hash){ if($hash{$key} == 3){ $max = $key if length($max) < length($key); } } print "$max\n"; __DATA__ strrringggg ssttrrringggg stttrrringgg
which is the longest common substring in this case so about your options, change 3 to 2 in the last cycletrrringgg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: longest common substring (with needed tweaks)
by R56 (Sexton) on Oct 28, 2013 at 16:37 UTC | |
by Lennotoecom (Pilgrim) on Oct 28, 2013 at 17:29 UTC | |
by Lennotoecom (Pilgrim) on Nov 05, 2013 at 15:20 UTC | |
by Lennotoecom (Pilgrim) on Nov 06, 2013 at 09:22 UTC |