2024 Dec 03rd
This commit is contained in:
parent
8fa58eca1b
commit
f1ac559664
1 changed files with 24 additions and 0 deletions
24
Python/2024/03/main.py
Normal file
24
Python/2024/03/main.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import re
|
||||||
|
input = open("input", 'r').read().strip()
|
||||||
|
|
||||||
|
# d = [line for line in input]
|
||||||
|
# d = [[val for val in line.strip()] for line in input]
|
||||||
|
|
||||||
|
def run(part2 = False):
|
||||||
|
sm = 0
|
||||||
|
x = re.findall(r"(mul\(\d*,\d*\))|(do\(\))|(don't\(\))", input)
|
||||||
|
enable = True
|
||||||
|
for item in x:
|
||||||
|
if enable and item[0]:
|
||||||
|
a, b = item[0].split(",")
|
||||||
|
a = int(a[4:])
|
||||||
|
b = int(b[:-1])
|
||||||
|
sm += a * b
|
||||||
|
elif item[1]:
|
||||||
|
enable = True
|
||||||
|
elif part2:
|
||||||
|
enable = False
|
||||||
|
return sm
|
||||||
|
|
||||||
|
print(run())
|
||||||
|
print(run(True))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue