use case in day3 2024
This commit is contained in:
parent
9cf965cf09
commit
8a4323bd16
1 changed files with 5 additions and 6 deletions
|
@ -21,13 +21,12 @@ for instruction <- Regex.scan(
|
||||||
input
|
input
|
||||||
), reduce: {true, 0} do
|
), reduce: {true, 0} do
|
||||||
{enabled?, acc} ->
|
{enabled?, acc} ->
|
||||||
(fn
|
case {enabled?, instruction} do
|
||||||
false, ["mul" <> _ | _] -> {false, acc}
|
{false, ["mul" <> _ | _]} -> {false, acc}
|
||||||
true, ["mul" <> _, _, a, b] -> {true, acc + String.to_integer(a) * String.to_integer(b)}
|
{true, ["mul" <> _, _, a, b]} -> {true, acc + String.to_integer(a) * String.to_integer(b)}
|
||||||
_, ["don" <> _ | _] -> {false, acc}
|
{_, ["don" <> _ | _]} -> {false, acc}
|
||||||
_, ["do()" | _] -> {true, acc}
|
{_, ["do()" | _]} -> {true, acc}
|
||||||
end
|
end
|
||||||
).(enabled?, instruction)
|
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue