浏览代码

Solve day 19

Taddeus Kroes 1 年之前
父节点
当前提交
3e57a679cf
共有 2 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      2024/19_towels.py
  2. 0 0
      2024/input/19

+ 16 - 0
2024/19_towels.py

@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+import sys
+from functools import cache
+
+@cache
+def possible(design, towels):
+    if not design:
+        return 1
+    return sum(possible(design[len(towel):], towels)
+               for towel in towels if design.startswith(towel))
+
+towels = tuple(sys.stdin.readline().rstrip().split(', '))
+designs = sys.stdin.read().split()
+pos = [possible(design, towels) for design in designs]
+print(sum(map(bool, pos)))
+print(sum(pos))

文件差异内容过多而无法显示
+ 0 - 0
2024/input/19


部分文件因为文件数量过多而无法显示