Skip to content

Commit 8e04c67

Browse files
committed
Fix some range complaints
1 parent 4838212 commit 8e04c67

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/2016/day_01.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ defmodule AdventOfCode.Y2016.Day01 do
8585
move(:south, rest, new_position, positions ++ positions_between([x, y], new_position))
8686
end
8787

88-
defp positions_between([x1, y], [x2, y]), do: x1..x2 |> Enum.map(&[&1, y])
89-
defp positions_between([x, y1], [x, y2]), do: y1..y2 |> Enum.map(&[x, &1])
88+
defp positions_between([x1, y], [x2, y]), do: range_between(x1, x2) |> Enum.map(&[&1, y])
89+
defp positions_between([x, y1], [x, y2]), do: range_between(y1, y2) |> Enum.map(&[x, &1])
9090

9191
defp merge_points(positions), do: positions |> Enum.chunk_by(& &1) |> Enum.map(&hd(&1))
9292

@@ -96,4 +96,7 @@ defmodule AdventOfCode.Y2016.Day01 do
9696
do:
9797
(MapSet.member?(history, position) && position) ||
9898
first_duplicate(rest, MapSet.put(history, position))
99+
100+
defp range_between(x1, x2) when x1 <= x2, do: x1..x2//1
101+
defp range_between(x1, x2), do: x1..x2//-1
99102
end

lib/2017/day_06.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ defmodule AdventOfCode.Y2017.Day06 do
1111

1212
def run(input \\ input()) do
1313
blocks = parse(input)
14-
{visited, blocks} = distribute_largest(blocks, %MapSet{})
15-
{second_visit, _} = distribute_largest(blocks, %MapSet{})
14+
{visited, blocks} = distribute_largest(blocks, MapSet.new([]))
15+
{second_visit, _} = distribute_largest(blocks, MapSet.new([]))
1616

1717
{Enum.count(visited) + 1, Enum.count(second_visit)}
1818
end

0 commit comments

Comments
 (0)