Day 4: Camp Cleanup
Mix.install([:kino])
Part 1
input = Kino.Input.textarea("Input")
defmodule M do
  def contains?([[s1, e1], [s2, e2]]) do
    (s1 >= s2 and e1 <= e2) or (s2 >= s1 and e2 <= e1)
  end
  def parse(pair) do
    pair
    |> String.split(",")
    |> Enum.map(fn s ->
      s
      |> String.split("-")
      |> Enum.map(&String.to_integer/1)
    end)
  end
end
input
|> Kino.Input.read()
|> String.split()
|> Enum.map(&M.parse/1)
|> Enum.map(&M.contains?/1)
|> Enum.count(fn x -> x end)
Part 2
defmodule M do
  def overlapped?([[s1, e1], [s2, e2]]) do
    s1 <= e2 and e1 >= s2
  end
  def parse(pair) do
    pair
    |> String.split(",")
    |> Enum.map(fn s ->
      s
      |> String.split("-")
      |> Enum.map(&String.to_integer/1)
    end)
  end
end
input
|> Kino.Input.read()
|> String.split()
|> Enum.map(&M.parse/1)
|> Enum.map(&M.overlapped?/1)
|> Enum.count(fn x -> x end)