We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4838212 commit 8e04c67Copy full SHA for 8e04c67
lib/2016/day_01.ex
@@ -85,8 +85,8 @@ defmodule AdventOfCode.Y2016.Day01 do
85
move(:south, rest, new_position, positions ++ positions_between([x, y], new_position))
86
end
87
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])
+ defp positions_between([x1, y], [x2, y]), do: range_between(x1, x2) |> Enum.map(&[&1, y])
+ defp positions_between([x, y1], [x, y2]), do: range_between(y1, y2) |> Enum.map(&[x, &1])
90
91
defp merge_points(positions), do: positions |> Enum.chunk_by(& &1) |> Enum.map(&hd(&1))
92
@@ -96,4 +96,7 @@ defmodule AdventOfCode.Y2016.Day01 do
96
do:
97
(MapSet.member?(history, position) && position) ||
98
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
102
lib/2017/day_06.ex
@@ -11,8 +11,8 @@ defmodule AdventOfCode.Y2017.Day06 do
11
12
def run(input \\ input()) do
13
blocks = parse(input)
14
- {visited, blocks} = distribute_largest(blocks, %MapSet{})
15
- {second_visit, _} = distribute_largest(blocks, %MapSet{})
+ {visited, blocks} = distribute_largest(blocks, MapSet.new([]))
+ {second_visit, _} = distribute_largest(blocks, MapSet.new([]))
16
17
{Enum.count(visited) + 1, Enum.count(second_visit)}
18
0 commit comments