From 766ae24cb27c2194b3b521c43f0929292aeb8901 Mon Sep 17 00:00:00 2001 From: Sloane Perrault Date: Wed, 21 Sep 2022 09:19:53 -0400 Subject: [PATCH] day 1 cleanup --- 2021/lib/advent_of_code/day01.ex | 21 +++++++------------ .../test/advent_of_code/day01/part_1_test.exs | 2 +- .../test/advent_of_code/day01/part_2_test.exs | 3 +-- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/2021/lib/advent_of_code/day01.ex b/2021/lib/advent_of_code/day01.ex index f4d9eef..9f69f13 100644 --- a/2021/lib/advent_of_code/day01.ex +++ b/2021/lib/advent_of_code/day01.ex @@ -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), - & 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 diff --git a/2021/test/advent_of_code/day01/part_1_test.exs b/2021/test/advent_of_code/day01/part_1_test.exs index 365f0a3..b1ca9a5 100644 --- a/2021/test/advent_of_code/day01/part_1_test.exs +++ b/2021/test/advent_of_code/day01/part_1_test.exs @@ -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 diff --git a/2021/test/advent_of_code/day01/part_2_test.exs b/2021/test/advent_of_code/day01/part_2_test.exs index a0c7115..7a09811 100644 --- a/2021/test/advent_of_code/day01/part_2_test.exs +++ b/2021/test/advent_of_code/day01/part_2_test.exs @@ -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 -