Skip to content

Commit 3b35754

Browse files
committed
Add solution to 2024-12-19
1 parent a37da74 commit 3b35754

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

2024/day19/solutions.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from functools import cache
2+
3+
4+
with open("input") as f:
5+
ls = f.read().strip().split("\n")
6+
7+
stripes, _, *patterns = ls
8+
stripes = stripes.split(", ")
9+
10+
11+
@cache
12+
def is_possible(pattern, op):
13+
if not pattern:
14+
return 1
15+
return op(
16+
is_possible(pattern[len(stripe) :], op)
17+
for stripe in stripes
18+
if pattern.startswith(stripe)
19+
)
20+
21+
22+
# Part 1 + 2
23+
for op in any, sum:
24+
print(sum(is_possible(pattern, op) for pattern in patterns))

0 commit comments

Comments
 (0)