Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Untitled notebook

aoc_2022_1.livemd

Untitled notebook

Section

file = Path.absname("Downloads/input-elves.txt")
{:ok, data} = File.read(file)
sum_elve = fn elve_data ->
  elve_data
  |> Enum.reduce(0, fn string, acc ->
    string
    |> Integer.parse()
    |> case do
      {int, ""} -> acc + int
      :error -> IO.inspect(string)
    end
  end)
end
data
|> String.split("\n\n")
|> Enum.map(fn elve_data ->
  elve_data
  |> String.split("\n")
  |> sum_elve.()
end)
|> Enum.sort()
|> Enum.reverse()
|> Enum.take(4)
|> Enum.filter(fn x -> x != "" end)
|> IO.inspect()
|> Enum.sum()