Longest common subsequence: Difference between revisions
Content added Content deleted
m (Swapped order of two paragraphs.) |
SqrtNegInf (talk | contribs) m (→header/Perl: future-proof for 5.36, use new bitwise string operator) |
||
Line 2,151: | Line 2,151: | ||
===Alternate letting regex do all the work=== |
===Alternate letting regex do all the work=== |
||
<syntaxhighlight lang="perl"> |
<syntaxhighlight lang="perl">use strict; |
||
use strict; # https://rosettacode.org/wiki/Longest_common_subsequence |
|||
use warnings; |
use warnings; |
||
use feature 'bitwise'; |
|||
print "lcs is ", lcs('thisisatest', 'testing123testing'), "\n"; |
print "lcs is ", lcs('thisisatest', 'testing123testing'), "\n"; |
||
Line 2,161: | Line 2,160: | ||
{ |
{ |
||
my ($c, $d) = @_; |
my ($c, $d) = @_; |
||
for my $len ( reverse 1 .. length($c & $d) ) |
for my $len ( reverse 1 .. length($c &. $d) ) |
||
{ |
{ |
||
"$c\n$d" =~ join '.*', ('(.)') x $len, "\n", map "\\$_", 1 .. $len and |
"$c\n$d" =~ join '.*', ('(.)') x $len, "\n", map "\\$_", 1 .. $len and |
||
Line 2,169: | Line 2,168: | ||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
lcs is |
<pre>lcs is tastiest</pre> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |