RosettaCodeData/Task/Longest-common-substring/Icon/longest-common-substring-2.icon
2026-04-30 12:34:36 -04:00

19 lines
459 B
Text

procedure main(A)
s1 := \A[1] | "thisisatest"
s2 := \A[2] | "testing123testing"
write(s1)
write(s2)
write("---")
write(lcs(s1,s2))
end
procedure lcs(s1,s2)
lc := ""
s1 ? every (tab(upto(s2)), c1 := move(1), cs:="") do {
while p2 := upto(c1, s2) do
while (c1 == s2[p2]) | break break do
(cs ||:= c1, p2 +:= 1, c1 := move(1))
if *cs > *lc then lc := cs
}
return lc
end