diff --git a/2024/d19.py b/2024/d19.py new file mode 100644 index 0000000..8c83912 --- /dev/null +++ b/2024/d19.py @@ -0,0 +1,30 @@ +from lib import get_data +from functools import cache + +data = get_data(__file__) +lines = data.splitlines() +patterns = set(lines[0].split(", ")) + + +@cache +def valid(line): + if line == "": + return 1 + r = 0 + for j in range(1, len(line) + 1): + sub = line[:j] + if sub in patterns: + r += valid(line[j:]) + return r + + +p1, p2 = 0, 0 +lines = lines[2:] +for line in lines: + v = valid(line.strip()) + if v > 0: + p1 += 1 + p2 += v + +print(p1) +print(p2) diff --git a/README.md b/README.md index 08d48ab..e9cacdc 100644 --- a/README.md +++ b/README.md @@ -309,5 +309,6 @@ and focus. Of course, learning more algorithms and techniques helps. - Day 16: ` >24h 24941 0 >24h 20575 0` - Day 17: `17:34:16 23722 0 >24h 17778 0` - Day 18: `14:35:01 20398 0 14:37:18 19550 0` -- Day 19: +- Day 19: `00:14:37 2001 0 00:19:43 1584 0` +- Day 20: