Longest common substring: Difference between revisions

m
(jq)
Line 213:
 
def set(i;j; value):
value assetpath([i,j]; $value);</lang>
| setpath([i,j]; $value);</lang>
 
'''Longest Common Substring''':
Line 225 ⟶ 224:
reduce range(0; b|length) as $j
(.;
if a[$i:$i+1] == b[$j:$j+1] then
(if $i == 0 or $j == 0 then .[0] |= set($i; $j; 1)
else (.[0] |= set($i; $j; .[$i-1][$j-1] + 1))
end) as end$x
| if .[0][ |= set($i][; $j]; > .[1] then$x)
| if $x > .[1] = .[0][$i][$j]then
| .[1] as= $mxx
| .[2] = a[1 + $i - $mxx : 1+$i+1] # output
else .
end
2,496

edits