RosettaCodeData/Task/Longest-common-substring/11l/longest-common-substring.11l

17 lines
447 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
F longest_common_substring(s1, s2)
V ir = 0
V jr = -1
L(i1) 0 .< s1.len
V? i2 = s2.find(s1[i1])
L i2 != N
V (j1, j2) = (i1, i2)
L j1 < s1.len & j2 < s2.len & s2[j2] == s1[j1]
I j1 - i1 >= jr - ir
(ir, jr) = (i1, j1)
j1++
j2++
i2 = s2.find(s1[i1], i2 + 1)
R s1[ir..jr]
print(longest_common_substring(thisisatest, testing123testing))