2024 day 3 python
This commit is contained in:
parent
6ebc4b9ae0
commit
828d855d6d
2 changed files with 25 additions and 0 deletions
19
2024/day03/day03.py
Normal file
19
2024/day03/day03.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import re
|
||||
|
||||
|
||||
def p1(s):
|
||||
return sum(int(a) * int(b) for a, b in re.findall(r"mul\((\d+),(\d+)\)", s))
|
||||
|
||||
|
||||
def p2(s):
|
||||
return sum(
|
||||
sum(p1(u) for u in re.split(r"do\(\)", t)[1:])
|
||||
for t in re.split(r"don't\(\)", "do()" + s)
|
||||
)
|
||||
|
||||
|
||||
with open("input") as fd:
|
||||
inp = fd.read()
|
||||
|
||||
print(p1(inp))
|
||||
print(p2(inp))
|
Loading…
Add table
Add a link
Reference in a new issue