Skip to content

Commit 2041ca4

Browse files
committed
Adding regex
1 parent d3f1b15 commit 2041ca4

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

aoc/2025/10/10.vn.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@
66
import heapq
77
from collections import defaultdict
88
from tqdm.auto import tqdm
9-
from collections import deque
9+
import re
1010

11-
def parse(buttons: str):
12-
buttons = buttons.strip().split()
11+
def parse(row: str):
12+
row = row.strip()
13+
goal = re.search(r"[#\.]+", row).group()
1314
goal = tuple(map(lambda x: int(x == "#"),
14-
buttons[0][1:-1]))
15-
size = len(goal)
16-
req = tuple(map(int, buttons[-1][1:-1].split(",")))
15+
goal))
16+
buttons = re.findall(r"\(((?:\d,*)+)", row)
1717
buttons = list(map(
18-
lambda s: tuple(map(int, s[1:-1].split(","))),
19-
buttons[1:-1]))
18+
lambda s: tuple(map(int, s.split(","))),
19+
buttons))
20+
req = list(
21+
map(int,
22+
re.search(r"{(.*)}", row).group(1).split(",")
23+
))
24+
25+
size = len(goal)
2026
for i in range(len(buttons)):
2127
r = [0 for _ in range(size)]
2228
for j in buttons[i]:

0 commit comments

Comments
 (0)