From 3b35754511c7c5b011005a365288c2735dd9c52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Fuglede=20J=C3=B8rgensen?= Date: Thu, 19 Dec 2024 08:52:36 +0100 Subject: [PATCH] Add solution to 2024-12-19 --- 2024/day19/solutions.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 2024/day19/solutions.py diff --git a/2024/day19/solutions.py b/2024/day19/solutions.py new file mode 100644 index 0000000..3697174 --- /dev/null +++ b/2024/day19/solutions.py @@ -0,0 +1,24 @@ +from functools import cache + + +with open("input") as f: + ls = f.read().strip().split("\n") + +stripes, _, *patterns = ls +stripes = stripes.split(", ") + + +@cache +def is_possible(pattern, op): + if not pattern: + return 1 + return op( + is_possible(pattern[len(stripe) :], op) + for stripe in stripes + if pattern.startswith(stripe) + ) + + +# Part 1 + 2 +for op in any, sum: + print(sum(is_possible(pattern, op) for pattern in patterns))