Skip to content

Instantly share code, notes, and snippets.

@tfwright

tfwright/1 Secret

Last active December 1, 2022 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfwright/1eff92471eb4ab727ec301851e31c230 to your computer and use it in GitHub Desktop.
Save tfwright/1eff92471eb4ab727ec301851e31c230 to your computer and use it in GitHub Desktop.
System.argv()
|> List.first()
|> File.read!()
|> String.split("\n\n")
|> Enum.map(fn elf_inventory ->
elf_inventory
|> String.split("\n")
|> Enum.flat_map(fn
"" -> []
cals -> [String.to_integer(cals)]
end)
|> Enum.sum()
end)
|> Enum.max()
|> IO.inspect()
System.argv()
|> List.first()
|> File.read!()
|> String.split("\n\n")
|> Enum.reduce([0, 0, 0], fn elf_inventory, top_3 ->
cal_sum =
elf_inventory
|> String.split("\n")
|> Enum.flat_map(fn
"" -> []
cals -> [String.to_integer(cals)]
end)
|> Enum.sum()
if cal_sum > List.first(top_3) do
Enum.sort([cal_sum | Enum.drop(top_3, 1)])
else
top_3
end
end)
|> Enum.sum()
|> IO.inspect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment