aoc2024/d19/run.py

7 lines
277 B
Python

import sys
from functools import cache
f = cache(lambda s: 1 if len(s)==0 else sum(f(s[len(r):]) for r in R if s.startswith(r)))
R, I = sys.stdin.read().strip().split("\n\n") ; R = R.split(", ")
print(sum(f(i)>0 for i in I.split("\n")))
print(sum(f(i) for i in I.split("\n")))