Skip to content

Instantly share code, notes, and snippets.

@NEbere
Created October 5, 2016 07:40
Show Gist options
  • Save NEbere/fbc744200f99d5b5fe850f44ebc0af6c to your computer and use it in GitHub Desktop.
Save NEbere/fbc744200f99d5b5fe850f44ebc0af6c to your computer and use it in GitHub Desktop.
// Codility Bbinary Gap Test
function solution($N) {
// write your code in PHP5.5
$binaryNumber = decbin($N); // binary conversion of number
$trimmed = trim($binaryNumber, 0); // trim to remove trailing zeros
$binaryGap = explode("1",$trimmed); // explode
$binaryCount = array_map('strlen', $binaryGap);
return max($binaryCount); // returns the longest binary gap
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment