24 lines
440 B
Elixir
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
|