1
0
Fork 0

day 1 cleanup

This commit is contained in:
Sloane Perrault 2022-09-21 09:19:53 -04:00
parent b9e9ecc85f
commit 766ae24cb2
3 changed files with 9 additions and 17 deletions

View file

@ -7,6 +7,7 @@ defmodule AdventOfCode.Day01 do
input_stream
|> Stream.map(&String.trim/1)
|> Stream.map(&String.to_integer/1)
|> Enum.to_list()
end
end
@ -22,22 +23,15 @@ defmodule AdventOfCode.Day01.Part1 do
@impl PuzzleSolver
def solve(input_stream) do
depth_stream =
input_stream
|> parse_input_stream()
|> Enum.to_list()
depths = parse_input_stream(input_stream)
Enum.zip_with(
depth_stream,
Enum.drop(depth_stream, 1),
&</2
Enum.zip_reduce(
depths,
Enum.drop(depths, 1),
0,
&if(&1 < &2, do: &3 + 1, else: &3)
)
|> Stream.filter(&is_true?/1)
|> Enum.count()
end
defp is_true?(true), do: true
defp is_true?(_), do: false
end
defmodule AdventOfCode.Day01.Part2 do
@ -53,7 +47,6 @@ defmodule AdventOfCode.Day01.Part2 do
@impl PuzzleSolver
def solve(input_stream) do
parse_input_stream(input_stream)
|> Enum.to_list()
|> window_increases()
end

View file

@ -1,7 +1,7 @@
defmodule AdventOfCode.Day01.Part1Test do
use AdventOfCode.PuzzleCase, module: AdventOfCode.Day01.Part1
test "returns :ok" do
test "solves for a small input" do
input = ~S"""
199
200

View file

@ -1,7 +1,7 @@
defmodule AdventOfCode.Day01.Part2Test do
use AdventOfCode.PuzzleCase, module: AdventOfCode.Day01.Part2
test "returns :ok" do
test "solves for a small input" do
input = ~S"""
199
200
@ -18,4 +18,3 @@ defmodule AdventOfCode.Day01.Part2Test do
assert_solution(input, 5)
end
end