DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Computes A Number From Two Strings
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





