Initial commit

This commit is contained in:
Geoffrey Frogeye 2024-12-25 12:58:02 +01:00
commit 97a4330bc0
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8
110 changed files with 7006 additions and 0 deletions

19
2024/3/one.py Normal file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env python3
import sys
import re
input_file = sys.argv[1]
with open(input_file) as fd:
lines = [line.rstrip() for line in fd.readlines()]
t = 0
reg = r"mul\(([0-9]+),([0-9]+)\)"
for line in lines:
for match in re.findall(reg, line):
ast, bst = match
a, b = int(ast), int(bst)
m = a * b
t += m
print(t)

26
2024/3/two.py Normal file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import sys
import re
input_file = sys.argv[1]
with open(input_file) as fd:
lines = [line.rstrip() for line in fd.readlines()]
t = 0
en = True
reg = r"mul\(([0-9]+),([0-9]+)\)|do\(\)|don't\(\)"
for line in lines:
for match in re.finditer(reg, line):
all = match.group(0)
if all == "do()":
en = True
elif all == "don't()":
en = False
elif en:
ast, bst = match.group(1), match.group(2)
a, b = int(ast), int(bst)
m = a * b
t += m
print(t)