in reply to Measuring Substrings Problem
This produces the required results for the testcases provided reasonably efficiently. Generalising the implementation is left as an exercise.
Basically, you replace spaces with nulls, OR the n-1 shorter strings together and then XOR the result with the longest string. You then count the number of nulls in the result.
The definition of "shorter" and "longest in that description is fuzzy :).
#! perl -slw use strict; my $s1 = 'GATTACGAGTGGCGCTCGTGTAACGGCA'; my $s2 = 'GATTACG GCGCTCG AACGGCA'; my $masked = $s1 ^ $s2; print scalar $masked =~ tr[\0][0]; my $s3 = 'GATTACGAGTGGCGCTCGTGTAACGGCA'; my $s4 = 'GATTACG '; my $s5 = ' TTACGAG CGTGTAA '; tr[ ][\0] for $s3, $s4, $s5; $masked = $s3 ^ ( $s4 | $s5 ); print scalar $masked =~ tr[\0][0]; my $s6 = ' GCTCGTG '; my $s7 = 'GATTACGAGTGGCGCTCGTGTAACGGCA'; my $s8 = ' TACGAGT '; my $s9 = ' GTGGCGC '; tr[ ][\0] for $s6, $s7, $s8, $s9; $masked = $s7 ^ ( $s6 | $s8 | $s9 ); print scalar $masked =~ tr[\0][0]; __END__ P:\test>junk2 21 16 17
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Substring Distance Problem
by Roy Johnson (Monsignor) on Apr 08, 2005 at 12:30 UTC | |
|
Re^2: Substring Distance Problem
by polettix (Vicar) on Apr 08, 2005 at 12:01 UTC | |
by tlm (Prior) on Apr 08, 2005 at 14:39 UTC |