Longest common subsequence: Difference between revisions
m
→{{header|Sidef}}: update
m (Replaced use of chains.size() with chains.empty().) |
m (→{{header|Sidef}}: update) |
||
Line 3,173:
<syntaxhighlight lang="ruby">func lcs(xstr, ystr) is cached {
xstr.is_empty && return xstr
ystr.is_empty && return ystr
var(x, xs, y, ys) = (xstr.
ystr.
if (x == y) {
x + lcs(xs, ys)
} else {
[lcs(xstr, ys), lcs(xs, ystr)].max_by { .len }
}
}
say lcs("thisisatest", "testing123testing")
{{out}}
<pre>
|