commit e5e8007197489a84d2fc3c499efe822642ba682e
parent f8944a95b16e2b09ad0d1b61ee5ba37d2755807f
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Thu, 11 Dec 2025 06:30:36 +0100
Day 11 2025
Diffstat:
4 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/2025/11/a.py b/2025/11/a.py
@@ -1,6 +1,12 @@
import fileinput
+a = {}
with fileinput.input() as lines:
for line in lines:
- ...
+ v, l2 = line[:-1].split(': ')
+ a[v] = l2.split(' ')
+def np(v):
+ return 1 if v == 'out' else sum(np(w) for w in a[v])
+
+print(np('you'))
diff --git a/2025/11/b.py b/2025/11/b.py
@@ -0,0 +1,16 @@
+import fileinput
+from functools import cache
+
+a = {}
+with fileinput.input() as lines:
+ for line in lines:
+ v, l2 = line[:-1].split(': ')
+ a[v] = l2.split(' ')
+
+@cache
+def np(v, d, f):
+ if v == 'out':
+ return 1 if d and f else 0
+ return sum(np(w, d or v == 'dac', f or v == 'fft') for w in a[v])
+
+print(np('svr', False, False))
diff --git a/2025/README.md b/2025/README.md
@@ -11,6 +11,7 @@ Example
```
Day -Part 1- -Part 2-
+ 11 00:14:22 00:21:19
10 00:27:43 11:51:51
9 00:05:05 02:11:41
8 00:29:14 00:33:02
@@ -213,3 +214,16 @@ AoC problem (see `../2023/24/24b.c`).
This time I left some comments in the code, so check out `10/b.py` if
you want to know the details.
+
+### Day 11: Reactor
+
+This is very easy, at least if you have ever worked with graphs. For
+part 1I have implemented a recursive function `np(v)` that counts the
+number of paths from a node `v` to `out`: it returns 1 if `v == out`,
+or the sum of `np(w)` for all neighbors `w` of `v` otherwise.
+
+For part 2 the function takes 2 extra parameters that denote whether
+or not we have passed through the two required intermediate nodes.
+
+The paths in part 1 are small enough that memoization is not required,
+but in part 2 we need to cache the intermediate results.
diff --git a/README.md b/README.md
@@ -14,4 +14,4 @@ See `year/README.md` for instructions on how to run my code.
|2022| 50 | Rust | Done in 2025 to learn Rust |
|2023| 50 | C | All solved by December 25, 2023 |
|2024| 50 | C++ | Each solved within 24h |
-|2025| 20 | Python | Work in progress... |
+|2025| 22 | Python | Work in progress... |