Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day3(s, *, part2=False):
- total = 0
- enable = True
- while s:
- pattern_mul = r'^mul\(([0-9]{1,3}),([0-9]{1,3})\)'
- if enable and (match := re.match(pattern_mul, s)):
- total += int(match[1]) * int(match[2])
- if s.startswith('do()'):
- enable = True
- if s.startswith("don't()") and part2:
- enable = False
- s = s[1:]
- return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement