diff --git a/2024/3/1.py b/2024/3/1.py new file mode 100644 index 0000000..76565da --- /dev/null +++ b/2024/3/1.py @@ -0,0 +1,17 @@ +import re + + +regex = r"mul\((\d{1,3}),(\d{1,3})\)" +c = re.compile(regex) + +def process_line(line): + return sum([int(x)*int(y) for x, y in c.findall(line)]) + +#test = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))" + +result = 0 +with open("input", "r") as fp: + while (line := fp.readline()): + result += process_line(line) + +print(f"The sum of all multiplications equals {result}.")