-
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
Ted Cassirer
committed
Dec 3, 2024
1 parent
534fa88
commit 77c248b
Showing
3 changed files
with
34 additions
and
8 deletions.
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,21 @@ | ||
import re | ||
|
||
|
||
def _mul_sum(data: str) -> int: | ||
return sum(int(n1) * int(n2) for n1, n2 in re.findall(r"mul\((\d+),(\d+)\)", data)) | ||
|
||
|
||
def part_a(data: str) -> int: | ||
return _mul_sum(data) | ||
|
||
|
||
def part_b(data: str) -> int: | ||
data = data.replace("\n", "") | ||
enabled_data = re.sub(r"((don't\(\)).+?(do\(\)))|(don't\(\).+?$)", "", data) | ||
return _mul_sum(enabled_data) | ||
|
||
|
||
if __name__ == "__main__": | ||
from aoc_cas.util import solve_with_examples | ||
|
||
solve_with_examples(year=2024, day=3) |
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 @@ | ||
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5)) | ||
mul | ||
- | ||
161 | ||
=== | ||
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5)) | ||
- | ||
48 |