From bf8c0f3a0ddd793ad4f227e4ad0f15ab3c52ba4f 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 | 22 ++++++++++++++++++++++ 1 file changed, 22 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..98cd4a6 --- /dev/null +++ b/2024/day19/solutions.py @@ -0,0 +1,22 @@ +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): + return not pattern or 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))