Skip to content

Commit

Permalink
Finish cleanup of 22B
Browse files Browse the repository at this point in the history
  • Loading branch information
duff committed Jan 14, 2019
1 parent a34a64b commit 6ced036
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/advent_2018/day_22.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ end
defmodule Advent2018.Day22 do
alias Advent2018.Day22.Survey

def part_a(depth, {x_target, y_target}) do
survey = initialize(depth, {x_target, y_target})

Enum.reduce(0..y_target, survey, fn y, acc ->
Enum.reduce(0..x_target, acc, fn x, acc ->
add_risk(acc, {x, y})
end)
end)
def part_a(depth, target_coordinates) do
initialize(depth, target_coordinates)
|> add_risks(target_coordinates)
|> risk_total
end

def part_b(depth, {x_target, y_target}) do
initialize(depth, {x_target, y_target})
def part_b(depth, target_coordinates) do
initialize(depth, target_coordinates)
|> add_regions
|> shortest_time
end
Expand Down Expand Up @@ -106,6 +101,14 @@ defmodule Advent2018.Day22 do
|> Enum.reject(fn {x, y} -> x < 0 || y < 0 end)
end

defp add_risks(survey, {x_target, y_target}) do
Enum.reduce(0..y_target, survey, fn y, acc ->
Enum.reduce(0..x_target, acc, fn x, acc ->
add_risk(acc, {x, y})
end)
end)
end

defp add_regions(survey) do
Enum.reduce(0..survey.y_max, survey, fn y, acc_x ->
Enum.reduce(0..survey.x_max, acc_x, fn x, acc ->
Expand Down

0 comments on commit 6ced036

Please sign in to comment.