3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function snake($k,$y,$str1,$str2){ $x = $y - $k; while($x < count($str1) && $y < count($str2) && $str1[$x] == $str2[$y]){ $x++; $y++; } return $y; } function edit_distance_onp($str1, $str2){ $s1 = count($str1) > count($str2) ? $str2 : $str1; $s2 = count($str1) > count($str2) ? $str1 : $str2; $fp = array(); $x = 0; $y = 0; $k = 0; $p = 0; $offset = count($s1) + 1; $delta = count($s2) - count($s1); for ($i = 0; $i < 15; $i++) $fp[$i] = -1; for ($p = 0; $fp[$delta + $offset] != count($s2); $p++) { for($k = -$p; $k < $delta; $k++) $fp[$k + $offset] = snake($k, max($fp[$k-1+$offset] + 1, $fp[$k+1+$offset]), $s1, $s2); for($k = $delta + $p; $k > $delta; $k--) $fp[$k + $offset] = snake($k, max($fp[$k-1+$offset] + 1, $fp[$k+1+$offset]), $s1, $s2); $fp[$delta + $offset] = snake($delta, max($fp[$delta-1+$offset] + 1, $fp[$delta+1+$offset]), $s1, $s2); } return $delta + ($p - 1) * 2; } $cha1[0] = "aaa"; $cha1[1] = "bbb"; $cha1[2] = "ccc"; $cha2[0] = "ddd"; $cha2[1] = "eee"; $cha2[2] = "fff"; echo edit_distance_onp($cha1,$cha2); ?>
Output for 4.3.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
6
Output for hhvm-3.10.0

Process exited with code 153.