Created
March 19, 2018 21:26
-
-
Save AlexR1712/8cabaaf174b93b13ff7d37e84a88b80c to your computer and use it in GitHub Desktop.
Revisions
-
AlexR1712 created this gist
Mar 19, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ <?php // Distancia Levenshtein en PHP (Sin usar la funciona nativa) function lev($s,$t) { $m = strlen($s); $n = strlen($t); for($i=0;$i<=$m;$i++) $d[$i][0] = $i; for($j=0;$j<=$n;$j++) $d[0][$j] = $j; for($i=1;$i<=$m;$i++) { for($j=1;$j<=$n;$j++) { $c = ($s[$i-1] == $t[$j-1])?0:1; $d[$i][$j] = min($d[$i-1][$j]+1,$d[$i][$j-1]+1,$d[$i-1][$j-1]+$c); } } return $d[$m][$n]; } echo var_dump(lev('calle', 'calla'));