Computes A Number From Two Strings
Join the DZone community and get the full member experience.Join For Free
def foobar(astring, bstring) Hash.new do |l,(i, j)| if l.key? [i, j] l[[i, j]] else a, b = astring[i], bstring[j] l[[i, j]] = case when !a, !b then 0 when a == b then 1 + l[[i + 1, j + 1]] else [ l[[i + 1, j]], l[[i, j + 1]] ].max end end end[[0, 0]] end
Opinions expressed by DZone contributors are their own.