Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Day 1: Calorie Counting

2022/elixir/day-01.livemd

Day 1: Calorie Counting

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

Input

input = Kino.Input.textarea("Input")

Part 1

Kino.Input.read(input)
|> String.split("\n\n")
|> Enum.map(fn group ->
  group
  |> String.split("\n")
  |> Enum.map(&String.to_integer(&1))
  |> Enum.sum()
end)
|> Enum.max()

Part 2

Kino.Input.read(input)
|> String.split("\n\n")
|> Enum.map(fn group ->
  group
  |> String.split("\n")
  |> Enum.map(&String.to_integer(&1))
  |> Enum.sum()
end)
|> Enum.sort(:desc)
|> Enum.take(3)
|> Enum.sum()