Skip to content

Commit 266e9d6

Browse files
committed
Refactor
1 parent 81ca42f commit 266e9d6

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

lib/2018/day_06.ex

+3-10
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ defmodule AdventOfCode.Y2018.Day06 do
4949

5050
for x <- xr..xl//-1, y <- yt..yb do
5151
{{x, y},
52-
points
53-
|> Enum.map(fn {xi, yi} ->
52+
Enum.map(points, fn {xi, yi} ->
5453
{{xi, yi}, manhattan_distance({xi, yi}, {x, y})}
5554
end)}
5655
end
@@ -60,9 +59,8 @@ defmodule AdventOfCode.Y2018.Day06 do
6059
defp nearest_point(distances) do
6160
distances
6261
|> Enum.sort_by(&elem(&1, 1))
63-
|> Enum.take(2)
6462
|> then(fn
65-
[{_, d}, {_, d}] -> nil
63+
[{_, d}, {_, d} | _] -> nil
6664
[{p, _} | _] -> p
6765
end)
6866
end
@@ -94,11 +92,6 @@ defmodule AdventOfCode.Y2018.Day06 do
9492
end
9593

9694
defp within_distance_threshold(distances, threshold) do
97-
distances
98-
|> Enum.sum_by(&elem(&1, 1))
99-
|> case do
100-
n when n < threshold -> 1
101-
_ -> 0
102-
end
95+
Enum.sum_by(distances, &elem(&1, 1)) < threshold && 1 || 0
10396
end
10497
end

0 commit comments

Comments
 (0)