From 28b761536bd9ed2ffb04cfbc32c364b66562ee4e Mon Sep 17 00:00:00 2001 From: ELmardi2 Date: Tue, 12 Jul 2016 16:07:58 +0200 Subject: [PATCH] Update hamming.php --- hamming.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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');