Levenshtein distance: Difference between revisions
m
→{{header|Raku}}: no temp. variable
m (→{{header|PL/M}}: Removed unused declarations) |
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: no temp. variable) |
||
Line 5,094:
=={{header|Raku}}==
(formerly Perl 6)
Implementation of the Wikipedia algorithm. Since column 0 and row 0 are used for base distances, the original algorithm would require us to compare "@s[$i-1] eq @t[$j-1]", and reference $m and $n separately. Prepending an unused value (undef) onto @s and @t makes their indices align with the $i,$j numbering of @d, and lets us use .end instead of $m,$n.
<lang perl6>sub levenshtein-distance ( Str $s, Str $t --> Int ) {
Line 5,113:
}
}
▲ say "Levenshtein distance('$s', '$t') == ", levenshtein-distance($s, $t);
}</lang>
{{out}}
|