Created
December 1, 2022 16:13
-
-
Save jstewart/7aa2e29882377237375807fdba52e838 to your computer and use it in GitHub Desktop.
AOC 2022 Day 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule AdventOfCode.Day01 do | |
def part1(args) do | |
args | |
|> into_bags() | |
|> Enum.max() | |
end | |
def part2(args) do | |
args | |
|> into_bags() | |
|> Enum.sort() | |
|> Enum.reverse() | |
|> Enum.take(3) | |
|> Enum.sum() | |
end | |
defp into_bags(args) do | |
args | |
|> Enum.chunk_by(fn line -> line == "" end) | |
|> Enum.filter(fn [first | _] -> first != "" end) | |
|> Enum.map(fn bag -> | |
bag | |
|> Enum.map(&String.to_integer/1) | |
|> Enum.sum() | |
end) | |
end | |
end |
Author
jstewart
commented
Dec 1, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment