Haskell Binary Gap
import Data.Char (intToDigit)
import Data.List (dropWhileEnd)
import Numeric (showIntAtBase)
binaryGap :: Int -> Int
binaryGap n = maximum (0 : map length (words spaced))
where
bin = showIntAtBase 2 intToDigit n ""
trimmed = dropWhileEnd (== '0') (dropWhile (== '0') bin)
spaced = map (\c -> if c == '1' then ' ' else c) trimmed
This turns the number into binary, ignores zeroes outside the edges, and finds the longest run of zeroes between 1s.