Levenshtein distance: Difference between revisions
Content added Content deleted
(→Functional/Folding Version: Work around ugly !!) |
|||
Line 2,015: | Line 2,015: | ||
return (0 until s.length).fold(initialRow, { previous, u -> |
return (0 until s.length).fold(initialRow, { previous, u -> |
||
(0 until t.length).fold( mutableListOf(u+1), { |
(0 until t.length).fold( mutableListOf(u+1), { |
||
row, v -> row.add( |
row, v -> row.add(minOf(row.last() + 1, |
||
previous[v+1] + 1, |
previous[v+1] + 1, |
||
previous[v] + charScore(s[u],t[v])) |
previous[v] + charScore(s[u],t[v]))) |
||
row |
row |
||
}) |
}) |