feat: Implement mul() instruction parsing and summation for Day 3

This commit is contained in:
Ruidy (aider) 2024-12-03 14:03:20 +01:00 committed by Ruidy
parent 787427de18
commit 70b2cf2086
No known key found for this signature in database
GPG key ID: E00F51288CB857CC

View file

@ -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}