diff --git a/2023/elixir/lib/2023/2.ex b/2023/elixir/lib/2023/2.ex index 6819069..fe46489 100644 --- a/2023/elixir/lib/2023/2.ex +++ b/2023/elixir/lib/2023/2.ex @@ -94,6 +94,22 @@ aoc 2023, 2 do |> Enum.sum() 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 diff --git a/README.md b/README.md index 45e8da4..7dd8c03 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ 1. [2020] **17/50** 🌟 1. [2021] **43/50** 🌟 1. [2022] **14/50** 🌟 -1. [2023] **3/50** 🌟 +1. [2023] **4/50** 🌟 [2015]: ./2015 [2017]: ./2017