Here is something basic in Perl to get you started. It is unclear if you mean substrings of subsequences. This deals with substrings. To understand it you will need to read up on what the substr(), push and sort functions do.
my $s1 = 'abcdefghijklmnopqrstuvwxyzabcdefgab'; my $s2 = 'abcdefgab'; my $MIN_LENGTH = 2; my @subseq = (); for my $i (0..length($s2)-$MIN_LENGTH) { for my $j ($MIN_LENGTH..length($s2)-$i) { push @subseq, substr($s2,$i,$j); } } print "$_\n" for @subseq; @subseq = sort{length($b)<=>length($a)}@subseq; SUBSEQ: for my $subseq (@subseq) { for my $i (0..length($s1)-length($subseq)) { if ($subseq eq substr($s1,$i,length($subseq))) { print "Match $subseq @ $i\n"; #last SUBSEQ } } }
In reply to Re: True Brute Force Longest Common Sub Sequence
by tachyon-II
in thread True Brute Force Longest Common Sub Sequence
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |