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
|
||||
), 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
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue