diff --git a/2024/Day-03/day03-1.py b/2024/Day-03/day03-1.py new file mode 100755 index 0000000..82f196d --- /dev/null +++ b/2024/Day-03/day03-1.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +import re +from math import prod + +if __name__ == '__main__': + with open('input.txt', 'r' ) as input_file: + input = input_file.read() + + res = 0 + for cmd in re.findall(r"mul\(\d+,\d+\)", input, flags=re.MULTILINE): + digits = [int(y) for y in ''.join([x for x in cmd if x.isdigit() or x == ',']).split(',')] + res += prod(digits) + print(res) diff --git a/2024/Day-03/day03-2.py b/2024/Day-03/day03-2.py new file mode 100755 index 0000000..5e56201 --- /dev/null +++ b/2024/Day-03/day03-2.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 + +import re +from math import prod + +if __name__ == '__main__': + with open('input.txt', 'r' ) as input_file: + input = input_file.read() + + res = 0 + en = True + for cmd in re.findall(r"(do\(\)|don\'t\(\)|mul\(\d+,\d+\))", input, flags=re.MULTILINE): + if cmd == 'do()': + en = True + continue + if cmd =='don\'t()': + en = False + continue + if en: + digits = [int(y) for y in ''.join([x for x in cmd if x.isdigit() or x == ',']).split(',')] + res += prod(digits) + print(res)