Last active
December 4, 2022 16:18
-
-
Save ThiagoPMaceda/cbb00958c5bb904cf6bcf0af54316193 to your computer and use it in GitHub Desktop.
AoC 2022, day 1 - Challenge 2
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
File.read!("day_1_input.txt") | |
|> String.split("\n", [trim: false]) | |
|> Enum.reduce({[], []}, fn input, {full_list, current_list} -> | |
case input do | |
"" -> {full_list ++ [current_list], []} | |
_ -> integer_parsed_input = String.to_integer(input) | |
{full_list, current_list ++ [integer_parsed_input]} | |
end | |
end) | |
|> elem(0) | |
|> Enum.reduce([], fn list, acc -> acc ++ [Enum.reduce(list, 0, &(&1 + &2))] end) | |
|> Enum.sort(&(&1 >= &2)) | |
|> Enum.take(3) | |
|> Enum.reduce(0, fn integer, acc -> acc + integer end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment