21 lines
823 B
Elixir
21 lines
823 B
Elixir
{:ok, contents} = File.read("input.txt")
|
|
elves = contents
|
|
|> String.split("\n\n", trim: true) # Split into elves.
|
|
|> Enum.map(fn elf -> elf # For each elf's food,
|
|
|> String.split("\n", trim: true) # split into calorie counts.
|
|
|> Enum.map(fn calories -> calories # For each calorie count,
|
|
|> String.to_integer # convert it to an integer.
|
|
end) # We're done with individual counts.
|
|
|> Enum.sum # Now add up each elf's calories.
|
|
end) # We're done with individual elves.
|
|
|
|
_part1 = elves # For part 1,
|
|
|> Enum.max # we just want the highest calorie count.
|
|
|> IO.inspect
|
|
|
|
_part2 = elves # For part 2,
|
|
|> Enum.sort # we can sort elves (default low->high)
|
|
|> Enum.take(-3) # and take the last 3 (highest 3) calorie counts,
|
|
|> Enum.sum # then add up those top 3 elves' calorie counts.
|
|
|> IO.inspect
|