From 3424be47bd0e020091bc5c8c1fcfc5917b50ce67 Mon Sep 17 00:00:00 2001 From: Samuel Owen Date: Fri, 29 Dec 2023 18:39:59 +0000 Subject: [PATCH] Add day2_solve_part_2 function to calculate accumulated powers --- lib/advent_of_code2023.ex | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/advent_of_code2023.ex b/lib/advent_of_code2023.ex index fac6991..75b1ee7 100644 --- a/lib/advent_of_code2023.ex +++ b/lib/advent_of_code2023.ex @@ -51,4 +51,16 @@ defmodule AdventOfCode2023 do Enum.sum(valid_id_ints) end + + def day2_solve_part_2(input_file_path) do + games_list = Day1.parse_file(input_file_path) + accumulated_powers = [] + + Enum.reduce(games_list, accumulated_powers, fn game, acc -> + minimal_map = Day2.get_minimal_map(game) + power = Day2.get_power_of_map(minimal_map) + [power | acc] + end) + |> Enum.sum() + end end