RosettaCodeData/Task/Longest-common-subsequence/BASIC256/longest-common-subsequence....

15 lines
417 B
Plaintext

function LCS(a, b)
if length(a) = 0 or length(b) = 0 then return ""
if right(a, 1) = right(b, 1) then
LCS = LCS(left(a, length(a) - 1), left(b, length(b) - 1)) + right(a, 1)
else
x = LCS(a, left(b, length(b) - 1))
y = LCS(left(a, length(a) - 1), b)
if length(x) > length(y) then return x else return y
end if
end function
print LCS("1234", "1224533324")
print LCS("thisisatest", "testing123testing")
end