2021 day7 didn't need to calc from 0, only min crab

This commit is contained in:
Adam Millerchip 2022-12-03 02:17:09 +09:00
parent 7ff40275c7
commit e183e04f23

View file

@ -2,7 +2,7 @@ defmodule Day7 do
def part1(input) do def part1(input) do
input input
|> Enum.frequencies() |> Enum.frequencies()
|> Enum.into(Map.new(0..Enum.max(input), &{&1, 0})) |> Enum.into(Map.new(Enum.min(input)..Enum.max(input), &{&1, 0}))
|> calculate_costs() |> calculate_costs()
|> Enum.min() |> Enum.min()
end end
@ -18,7 +18,7 @@ defmodule Day7 do
def part2(input) do def part2(input) do
input input
|> Enum.frequencies() |> Enum.frequencies()
|> Enum.into(Map.new(0..Enum.max(input), &{&1, 0})) |> Enum.into(Map.new(Enum.min(input)..Enum.max(input), &{&1, 0}))
|> calculate_sum_costs() |> calculate_sum_costs()
|> Enum.min() |> Enum.min()
end end