-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathday_01.ex
More file actions
31 lines (27 loc) · 706 Bytes
/
day_01.ex
File metadata and controls
31 lines (27 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
defmodule AdventOfCode.Y2022.Day01 do
@moduledoc """
--- Day 1: Calorie Counting ---
Problem Link: https://adventofcode.com/2022/day/1
Difficulty: xs
Tags: sequence
"""
alias AdventOfCode.Helpers.{InputReader, Transformers}
def input, do: InputReader.read_from_file(2022, 1)
def run(input \\ input()) do
calories = parse(input)
{
Enum.max(calories),
calories |> Enum.sort(:desc) |> Enum.take(3) |> Enum.sum()
}
end
def parse(data) do
data
|> String.split(~r{(\r\n\r\n|\r\r|\n\n)}, trim: true)
|> Enum.map(fn calories ->
calories
|> Transformers.lines()
|> Enum.map(&String.to_integer/1)
|> Enum.sum()
end)
end
end