aoc/22/lib/days/day1.ex
2023-12-04 10:25:33 +01:00

24 lines
440 B
Elixir

defmodule AOC.Day1 do
use AOC.Day, day: 1
def parse_input(lines) do
lines
|> Enum.chunk_by(&(&1 == ""))
|> Enum.reject(&(&1 == [""]))
|> Enum.map(fn l -> Enum.map(l, &String.to_integer/1) end)
end
def part1(input) do
input
|> Enum.map(&Enum.sum/1)
|> Enum.max()
end
def part2(input) do
input
|> Enum.map(&Enum.sum/1)
|> Enum.sort(:desc)
|> Enum.take(3)
|> Enum.sum()
end
end