use case in day3 2024

This commit is contained in:
Caleb Webber 2024-12-03 09:30:24 -05:00
parent 9cf965cf09
commit 8a4323bd16

View file

@ -21,13 +21,12 @@ for instruction <- Regex.scan(
input
), reduce: {true, 0} do
{enabled?, acc} ->
(fn
false, ["mul" <> _ | _] -> {false, acc}
true, ["mul" <> _, _, a, b] -> {true, acc + String.to_integer(a) * String.to_integer(b)}
_, ["don" <> _ | _] -> {false, acc}
_, ["do()" | _] -> {true, acc}
case {enabled?, instruction} do
{false, ["mul" <> _ | _]} -> {false, acc}
{true, ["mul" <> _, _, a, b]} -> {true, acc + String.to_integer(a) * String.to_integer(b)}
{_, ["don" <> _ | _]} -> {false, acc}
{_, ["do()" | _]} -> {true, acc}
end
).(enabled?, instruction)
end
```