From 06ca6eba41d565e618d73dc5aed7618241b8c5ab Mon Sep 17 00:00:00 2001 From: Adam Millerchip Date: Tue, 3 Dec 2024 16:50:47 +0900 Subject: [PATCH] Slightly cleaner without capture: :all_but_first for part 2 --- 2024/day3.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/2024/day3.exs b/2024/day3.exs index db1390b..641f748 100755 --- a/2024/day3.exs +++ b/2024/day3.exs @@ -7,12 +7,12 @@ defmodule Day3 do end def part2(input) do - Regex.scan(~r/mul\((\d+),(\d+)\)|(do\(\))|(don't\(\))/, input, capture: :all_but_first) + Regex.scan(~r/mul\((\d+),(\d+)\)|do\(\)|don't\(\)/, input) |> Enum.reduce({0, :process}, fn - ["", "", "do()"], {sum, _} -> {sum, :process} - ["", "", "", "don't()"], {sum, _} -> {sum, :skip} + ["do()"], {sum, _} -> {sum, :process} + ["don't()"], {sum, _} -> {sum, :skip} _, {sum, :skip} -> {sum, :skip} - [a, b], {sum, :process} -> {sum + String.to_integer(a) * String.to_integer(b), :process} + [_, a, b], {sum, :process} -> {sum + String.to_integer(a) * String.to_integer(b), :process} end) |> elem(0) end