Advent of Code 2024 Day 1 Part 1
Mix.install([
{:kino_aoc, "~> 0.1"}
])
Get Inputs
{:ok, puzzle_input} =
KinoAOC.download_puzzle("2024", "1", System.fetch_env!("LB_SESSION"))
My answer
{left_list, right_list} =
puzzle_input
|> String.split("\n")
|> Enum.map(fn row ->
row
|> String.split(" ")
|> Enum.filter(&(&1 != ""))
|> Enum.map(&String.to_integer(&1))
end)
|> Enum.map(fn [a, b] -> {a, b} end)
|> Enum.unzip()
Enum.zip(Enum.sort(left_list), Enum.sort(right_list))
|> Enum.map(fn {left, right} -> abs(left - right) end)
|> Enum.sum()