mirror of
https://github.com/rjNemo/ai_advent_code_2024
synced 2026-06-12 05:26:39 +00:00
feat: Implement mul() instruction parsing and summation for Day 3
This commit is contained in:
parent
787427de18
commit
70b2cf2086
1 changed files with 11 additions and 2 deletions
|
|
@ -47,8 +47,17 @@ defmodule AdventCode2024.Solutions.Day03 do
|
||||||
|
|
||||||
defp solve_content(""), do: {:error, :no_input}
|
defp solve_content(""), do: {:error, :no_input}
|
||||||
defp solve_content(content) when is_binary(content) and content != "" do
|
defp solve_content(content) when is_binary(content) and content != "" do
|
||||||
# TODO: Implement solution for part 1
|
result =
|
||||||
{:ok, 0}
|
~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
|
end
|
||||||
|
|
||||||
defp solve_part2_content(""), do: {:error, :no_input}
|
defp solve_part2_content(""), do: {:error, :no_input}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue