16 lines
386 B
Text
16 lines
386 B
Text
val lcs = fn(s1, s2) {
|
|
var l, r, sublen = 1, 0, 0
|
|
for i of s1 {
|
|
for j in i .. len(s1) {
|
|
if not matching(s2, by=s2s(s1, of=i .. j)): break
|
|
if sublen <= j - i {
|
|
l, r = i, j
|
|
sublen = j - i
|
|
}
|
|
}
|
|
}
|
|
if r == 0: return ""
|
|
s2s s1, of=l .. r
|
|
}
|
|
|
|
writeln lcs("thisisatest", "testing123testing")
|