diff --git a/2024/day19/solutions.py b/2024/day19/solutions.py new file mode 100644 index 0000000..2c1921d --- /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 = [x.strip() for x in 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))