summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFanDabbyDoozy <ps20163152@student.vsa.edu.hk>2024-12-04 22:11:31 +0800
committerGitHub <noreply@github.com>2024-12-04 22:11:31 +0800
commitdc976d3cba3652037991b3b000c752e9dda83f2b (patch)
treecb0215a721201082d498036a8132a405868b24d5
parentcf052f66f8644d7271f25ea24624737e8556d301 (diff)
Create 3A.py
-rw-r--r--2024/3A.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/2024/3A.py b/2024/3A.py
new file mode 100644
index 0000000..2c7d249
--- /dev/null
+++ b/2024/3A.py
@@ -0,0 +1,21 @@
+import re
+
+with open('3.txt', 'r') as f:
+ data = f.read()
+
+mul = r'mul\(\d+,\d+\)'
+matches = re.findall(mul, data)
+
+lmuls = []
+lmuls.extend(matches)
+
+ints = [l.split("mul(")[1].rstrip(')') for l in lmuls]
+print(ints)
+
+muls = 0
+
+for i in ints:
+ n1, n2 = map(int, i.split(','))
+ print(n1, n2)
+ muls += n1 * n2
+print(muls)