solve 2023 2.2
This commit is contained in:
parent
5820ac1c3b
commit
d0ddaacfbd
2 changed files with 18 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue