Slide 167
Slide 167 text
Algorithm
str2.each_char.each_with_index do |char1,i|
str1.each_char.each_with_index do |char2, j|
if char1 == char2
puts [:skip, matrix[i][j]].inspect
matrix[i + 1 ][j + 1 ] = matrix[i][j]
else
actions = {
deletion: matrix[i][j + 1] + 1,
insert: matrix[i + 1][j] + 1,
substitution: matrix[i][j] + 1
}
action = actions.sort {|(k,v), (k2, v2)| v <=> v2 }.first
puts action.inspect
matrix[i + 1 ][j + 1 ] = action.last
end
each_step.call(matrix) if each_step
end
end