2025: improve folder names
This commit is contained in:
18
2024/03/puzzle1.py
Normal file
18
2024/03/puzzle1.py
Normal file
@ -0,0 +1,18 @@
|
||||
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))"
|
||||
|
||||
if __name__ == "__main__":
|
||||
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}.")
|
||||
Reference in New Issue
Block a user