RosettaCodeData/Task/Longest-common-substring/SETL/longest-common-substring.setl

18 lines
448 B
Plaintext

program longest_common_substring;
print(lcs("thisisatest", "testing123testing"));
proc lcs(s1, s2);
if #s1 < #s2 then [s1, s2] := [s2, s1]; end if;
loop for l in [#s2, #s2-1..1] do
loop for s in [1..#s2-l+1] do
if (substr := s2(s..s+l)) in s1 then
return substr;
end if;
end loop;
end loop;
return "";
end proc;
end program;