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;