diff --git a/hamming.php b/hamming.php index b457e65..198eed1 100644 --- a/hamming.php +++ b/hamming.php @@ -5,9 +5,16 @@ // convenience to get you started writing code faster. // -function distance($a, $b) -{ - // - // YOUR CODE GOES HERE - // +function hamdist($x, $y){ + for($dist = 0, $val = $x ^ $y; $val; ++$dist){ + $val &= $val - 1; + } + return $dist; } + +function hamdist_str($x, $y){ + return hamdist(bindec($x), bindec($y)); +} + + +echo hamdist_str('GAGCCTACTAACGGGAT,CATCGTAATGACGGCCT');