D
Dilbert
I have a question about the Perl Module Algorithm:
iff.
I want to use Algorithm:
iff to calculate the diff of the two
sequences "ab" and "a1bab", the "LCS" (the "Longest Common Sequence")
is a length of 2.
Theoretically there are 3 solutions with LCS = 2:
Solution 1:
---ab
a1bab
Solution 2:
a-b--
a1bab
Solution 3:
a---b
a1bab
I understand that any of those 3 solutions could be returned by
Algorithm:
iff, but I would argue that solution 1 is "better" than
solution 2 or 3, because solution 1 changes only once between '-' and
[ab], whereas solution 2 and 3 change more than once between '-' and
[ab].
This is my Perl program:
use strict;
use warnings;
use 5.010;
use Algorithm:
iff;
use Data:
umper;
my @old = split //, 'ab';
my @new = split //, 'a1bab';
my $d = Algorithm:
iff::sdiff(\@old, \@new);
my $line = Dumper($d);
$line =~ s{\s}''xmsg;
say $line;
The output is
$VAR1=[['u','a','a'],['+','','1'],['+','','b'],['+','','a'],
['u','b','b']];
This is in fact Solution 3:
a---b
a1bab
How can I teach Algorithm:
iff to choose Solution 1 (the best of the
3 possibilities) ?
I want to use Algorithm:
sequences "ab" and "a1bab", the "LCS" (the "Longest Common Sequence")
is a length of 2.
Theoretically there are 3 solutions with LCS = 2:
Solution 1:
---ab
a1bab
Solution 2:
a-b--
a1bab
Solution 3:
a---b
a1bab
I understand that any of those 3 solutions could be returned by
Algorithm:
solution 2 or 3, because solution 1 changes only once between '-' and
[ab], whereas solution 2 and 3 change more than once between '-' and
[ab].
This is my Perl program:
use strict;
use warnings;
use 5.010;
use Algorithm:
use Data:
my @old = split //, 'ab';
my @new = split //, 'a1bab';
my $d = Algorithm:
my $line = Dumper($d);
$line =~ s{\s}''xmsg;
say $line;
The output is
$VAR1=[['u','a','a'],['+','','1'],['+','','b'],['+','','a'],
['u','b','b']];
This is in fact Solution 3:
a---b
a1bab
How can I teach Algorithm:
3 possibilities) ?