DEV Community

loading...

Discussion on: Daily Challenge #31 - Count IPv4 Addresses

Collapse
brightone profile image
Oleksii Filonenko

Elixir:

defmodule IP do
  import Bitwise

  def between(from, to),
    do: abs(to_integer(to) - to_integer(from))

  defp to_integer(ip) do
    ip
    |> String.split(".")
    |> Enum.reduce(0, fn part, acc -> acc <<< 8 ||| String.to_integer(part) end)
  end
end