Advent of Code 2024 Day 1 Part 2
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()
left_list
|> Enum.map(fn left ->
left * Enum.count(right_list, fn right -> left == right end)
end)
|> Enum.sum()