Skip to content

Instantly share code, notes, and snippets.

@ThiagoPMaceda
Last active December 4, 2022 16:19
Show Gist options
  • Save ThiagoPMaceda/1fceec904b2d70d3f6162b72c1be93c5 to your computer and use it in GitHub Desktop.
Save ThiagoPMaceda/1fceec904b2d70d3f6162b72c1be93c5 to your computer and use it in GitHub Desktop.
AoC 2022, day 1 - Challenge 1
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.max()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment