RosettaCodeData/Task/Longest-common-subsequence/Phix/longest-common-subsequence-1.phix
2018-08-17 15:15:24 +01:00

20 lines
526 B
Text

function lcs(sequence a, b)
sequence res = ""
if length(a) and length(b) then
if a[$]=b[$] then
res = lcs(a[1..-2],b[1..-2])&a[$]
else
sequence l = lcs(a,b[1..-2]),
r = lcs(a[1..-2],b)
res = iff(length(l)>length(r)?l:r)
end if
end if
return res
end function
constant tests = {{"1234","1224533324"},
{"thisisatest","testing123testing"}}
for i=1 to length(tests) do
string {a,b} = tests[i]
?lcs(a,b)
end for