Skip to content

Commit 891a5ea

Browse files
committed
Inline function to avoid passing arg
1 parent d4aad95 commit 891a5ea

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

2024/src/aoc/days/day19.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ def parse_input(data: str) -> tuple[tuple[str, ...], list[str]]:
99
return tuple(patterns.split(", ")), designs.split("\n")
1010

1111

12-
@functools.cache
13-
def is_possible(design: str, patterns: tuple[str, ...]) -> bool:
14-
if not design:
15-
return 1
16-
17-
return sum(
18-
is_possible(design[len(pat) :], patterns)
19-
for pat in patterns
20-
if design.startswith(pat)
21-
)
22-
23-
2412
class DayRunner(CombinedRunner):
2513
@classmethod
2614
def run_both(cls, input: str) -> int:
@@ -29,8 +17,19 @@ def run_both(cls, input: str) -> int:
2917
possible = 0
3018
ways = 0
3119

20+
@functools.cache
21+
def is_possible(design: str) -> bool:
22+
if not design:
23+
return 1
24+
25+
return sum(
26+
is_possible(design[len(pat) :])
27+
for pat in patterns
28+
if design.startswith(pat)
29+
)
30+
3231
for design in designs:
33-
if (solve := is_possible(design, patterns)) > 0:
32+
if (solve := is_possible(design)) > 0:
3433
possible += 1
3534
ways += solve
3635

0 commit comments

Comments
 (0)