AOC 2022 - Day 1 (Elixir Solution)

AOC 2022-01 (Calories)

Mix.install([
  {:kino, "~> 0.7.0"}
])

Input

The Elves take turns writing down the number of Calories contained by the various meals, snacks, rations, etc. that they've brought with them, one item per line. Each Elf separates their own inventory from the previous Elf's inventory (if any) by a blank line.

input = Kino.Input.textarea("Input")
elfs =
  input
  |> Kino.Input.read()
  |> String.split("\n\n")

calories_by_elf =
  Enum.map(elfs, fn elf -> String.split(elf) |> Enum.map(&String.to_integer/1) |> Enum.sum() end)

Part 1

How many calories is the elf with the most calories carrying?

Enum.max(calories_by_elf)

Part 2

How many calories are the three elfs with the most calories carrying?

calories_by_elf
|> Enum.sort()
|> Enum.reverse()
|> Enum.take(3)
|> Enum.sum()