-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"""2024 - Day 3 Part 1: Mull It Over""" | ||
|
||
import re | ||
|
||
|
||
def solve(task: str) -> int: | ||
result = re.findall(r"mul\((\d+),(\d+)\)", task) | ||
return sum(int(a) * int(b) for a, b in result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""2024 - Day 3 Part 2: Mull It Over""" | ||
|
||
import re | ||
|
||
|
||
def solve(task: str) -> int: | ||
result = re.findall(r"mul\((\d+),(\d+)\)|(do\(\))|(don't\(\))", task) | ||
|
||
ans = 0 | ||
skip = False | ||
|
||
for a, b, do, dnt in result: | ||
if dnt: | ||
skip = True | ||
elif do: | ||
skip = False | ||
elif skip: | ||
continue | ||
else: | ||
a = int(a) | ||
b = int(b) | ||
ans += a * b | ||
|
||
return ans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"""2024 - Day 3 Part 1: Mull It Over""" | ||
|
||
from src.year2024.day03a import solve | ||
|
||
|
||
def test_solve(): | ||
task = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))" | ||
assert solve(task) == 161 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"""2024 - Day 3 Part 2: Mull It Over""" | ||
|
||
from src.year2024.day03b import solve | ||
|
||
|
||
def test_solve(): | ||
task = "xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))" | ||
assert solve(task) == 48 |