Last active
December 1, 2024 20:04
-
-
Save Dzol/1ac19cb4293d55a924f3c3211cdd7ac9 to your computer and use it in GitHub Desktop.
AOC 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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