Elixir Binary Gap
defmodule BinaryGap do
def binary_gap(n) do
n
|> Integer.to_string(2)
|> String.trim("0")
|> String.split("1")
|> Enum.map(&String.length/1)
|> Enum.max()
end
end
This turns the number into binary, ignores zeroes outside the edges, and finds the longest run of zeroes between 1s.