From 70b2cf2086d4af9478f31135d48653192b3d31c2 Mon Sep 17 00:00:00 2001 From: "Ruidy (aider)" Date: Tue, 3 Dec 2024 14:03:20 +0100 Subject: [PATCH] feat: Implement mul() instruction parsing and summation for Day 3 --- lib/advent_code2024/solutions/day03/day3.ex | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/advent_code2024/solutions/day03/day3.ex b/lib/advent_code2024/solutions/day03/day3.ex index 6e3ec72..e5b13d9 100644 --- a/lib/advent_code2024/solutions/day03/day3.ex +++ b/lib/advent_code2024/solutions/day03/day3.ex @@ -47,8 +47,17 @@ defmodule AdventCode2024.Solutions.Day03 do defp solve_content(""), do: {:error, :no_input} defp solve_content(content) when is_binary(content) and content != "" do - # TODO: Implement solution for part 1 - {:ok, 0} + result = + ~r/mul\((\d{1,3}),(\d{1,3})\)/ + |> Regex.scan(content, capture: :all_but_first) + |> Enum.map(fn [x, y] -> + {x_int, _} = Integer.parse(x) + {y_int, _} = Integer.parse(y) + x_int * y_int + end) + |> Enum.sum() + + {:ok, result} end defp solve_part2_content(""), do: {:error, :no_input}