day_3
For part 1, matching all regexes like mul(1,4)
, capturing the numbers and then
summing the products is enough.
For part 2, we can non-greedily match everything between don't()
and do()
(or line end)
and replace that with an empty string, as we don’t want to consider those blocks.
This leaves us with the same problem as part 1, which means we can reuse the same function.
Functions
pub fn get_mult_sum(s: String) -> Int
Parse a string and return the sum of the products defined by mul(a, b)
expressions
pub fn remove_dont_blocks(input_string: String) -> String
Remove everything between a don't()
and a do()
, spanning multiple lines