2024 Day 3

This commit is contained in:
2024-12-03 12:34:54 +00:00
parent 95c6129c43
commit d81a288185
2 changed files with 36 additions and 0 deletions

14
2024/Day-03/day03-1.py Executable file
View File

@@ -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)

22
2024/Day-03/day03-2.py Executable file
View File

@@ -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)