RosettaCodeData/Task/Longest-common-substring/Langur/longest-common-substring.langur
2024-04-19 16:56:29 -07:00

16 lines
407 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(s2s(.s1, .i .. .j), .s2): break
if .sublen <= .j - .i {
.l, .r = .i, .j
.sublen = .j - .i
}
}
}
if .r == 0: return ""
s2s .s1, .l .. .r
}
writeln .lcs("thisisatest", "testing123testing")