Skip to content

Instantly share code, notes, and snippets.

@Dzol
Last active December 1, 2024 20:04
Show Gist options
  • Save Dzol/1ac19cb4293d55a924f3c3211cdd7ac9 to your computer and use it in GitHub Desktop.
Save Dzol/1ac19cb4293d55a924f3c3211cdd7ac9 to your computer and use it in GitHub Desktop.
AOC 2024
# Part I
x
|> String.split()
|> Enum.map(&String.to_integer/1)
|> Enum.chunk_every(2)
|> Enum.map(&List.to_tuple/1)
|> Enum.unzip()
|> then(fn {lhs, rhs} ->
lhs = Enum.sort(lhs)
rhs = Enum.sort(rhs)
[lhs, rhs]
end)
|> Enum.zip()
|> Enum.map(fn {l, r} -> abs(l - r) end)
|> Enum.sum()
# Part II
x
|> String.split()
|> Enum.map(&String.to_integer/1)
|> Enum.chunk_every(2)
|> Enum.map(&List.to_tuple/1)
|> Enum.unzip()
|> then(fn {lhs, rhs} ->
for l <- lhs do
l * Enum.count(rhs, &(&1 === l))
end
end)
|> Enum.sum()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment