1
0
Fork 0

solve 2023 2.2

This commit is contained in:
sloane 2023-12-02 09:47:15 -05:00
parent 5820ac1c3b
commit d0ddaacfbd
No known key found for this signature in database
2 changed files with 18 additions and 2 deletions

View file

@ -94,6 +94,22 @@ aoc 2023, 2 do
|> Enum.sum() |> Enum.sum()
end end
def p2(_input) do def p2(input) do
input
|> read_games()
|> Stream.map(&elem(&1, 1))
|> Stream.map(&calculate_power/1)
|> Enum.sum()
end
defp calculate_power(dice) do
{reds, greens, blues} =
dice
|> Enum.reduce({0, 0, 0}, fn d, {r, g, b} ->
{max(Map.get(d, "red", 0), r), max(Map.get(d, "green", 0), g),
max(Map.get(d, "blue", 0), b)}
end)
reds * blues * greens
end end
end end

View file

@ -14,7 +14,7 @@
1. [2020] **17/50** 🌟 1. [2020] **17/50** 🌟
1. [2021] **43/50** 🌟 1. [2021] **43/50** 🌟
1. [2022] **14/50** 🌟 1. [2022] **14/50** 🌟
1. [2023] **3/50** 🌟 1. [2023] **4/50** 🌟
[2015]: ./2015 [2015]: ./2015
[2017]: ./2017 [2017]: ./2017