aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-12-11 06:30:36 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-12-11 06:30:36 +0100
commite5e8007197489a84d2fc3c499efe822642ba682e (patch)
tree72666ca39016efa3df9efaee3e9eaa88ad18d8e9
parentf8944a95b16e2b09ad0d1b61ee5ba37d2755807f (diff)
downloadaoc-e5e8007197489a84d2fc3c499efe822642ba682e.tar.gz
aoc-e5e8007197489a84d2fc3c499efe822642ba682e.zip
Day 11 2025
-rw-r--r--2025/11/a.py8
-rw-r--r--2025/11/b.py16
-rw-r--r--2025/README.md14
-rw-r--r--README.md2
4 files changed, 38 insertions, 2 deletions
diff --git a/2025/11/a.py b/2025/11/a.py
index 5fdb11b..cf06b6a 100644
--- a/2025/11/a.py
+++ b/2025/11/a.py
@@ -1,6 +1,12 @@
1import fileinput 1import fileinput
2 2
3a = {}
3with fileinput.input() as lines: 4with fileinput.input() as lines:
4 for line in lines: 5 for line in lines:
5 ... 6 v, l2 = line[:-1].split(': ')
7 a[v] = l2.split(' ')
6 8
9def np(v):
10 return 1 if v == 'out' else sum(np(w) for w in a[v])
11
12print(np('you'))
diff --git a/2025/11/b.py b/2025/11/b.py
new file mode 100644
index 0000000..8fdcc8b
--- /dev/null
+++ b/2025/11/b.py
@@ -0,0 +1,16 @@
1import fileinput
2from functools import cache
3
4a = {}
5with fileinput.input() as lines:
6 for line in lines:
7 v, l2 = line[:-1].split(': ')
8 a[v] = l2.split(' ')
9
10@cache
11def np(v, d, f):
12 if v == 'out':
13 return 1 if d and f else 0
14 return sum(np(w, d or v == 'dac', f or v == 'fft') for w in a[v])
15
16print(np('svr', False, False))
diff --git a/2025/README.md b/2025/README.md
index 09d97c1..951213c 100644
--- a/2025/README.md
+++ b/2025/README.md
@@ -11,6 +11,7 @@ Example
11 11
12``` 12```
13Day -Part 1- -Part 2- 13Day -Part 1- -Part 2-
14 11 00:14:22 00:21:19
14 10 00:27:43 11:51:51 15 10 00:27:43 11:51:51
15 9 00:05:05 02:11:41 16 9 00:05:05 02:11:41
16 8 00:29:14 00:33:02 17 8 00:29:14 00:33:02
@@ -213,3 +214,16 @@ AoC problem (see `../2023/24/24b.c`).
213 214
214This time I left some comments in the code, so check out `10/b.py` if 215This time I left some comments in the code, so check out `10/b.py` if
215you want to know the details. 216you want to know the details.
217
218### Day 11: Reactor
219
220This is very easy, at least if you have ever worked with graphs. For
221part 1I have implemented a recursive function `np(v)` that counts the
222number of paths from a node `v` to `out`: it returns 1 if `v == out`,
223or the sum of `np(w)` for all neighbors `w` of `v` otherwise.
224
225For part 2 the function takes 2 extra parameters that denote whether
226or not we have passed through the two required intermediate nodes.
227
228The paths in part 1 are small enough that memoization is not required,
229but in part 2 we need to cache the intermediate results.
diff --git a/README.md b/README.md
index 94f6a3f..f52faa9 100644
--- a/README.md
+++ b/README.md
@@ -14,4 +14,4 @@ See `year/README.md` for instructions on how to run my code.
14|2022| 50 | Rust | Done in 2025 to learn Rust | 14|2022| 50 | Rust | Done in 2025 to learn Rust |
15|2023| 50 | C | All solved by December 25, 2023 | 15|2023| 50 | C | All solved by December 25, 2023 |
16|2024| 50 | C++ | Each solved within 24h | 16|2024| 50 | C++ | Each solved within 24h |
17|2025| 20 | Python | Work in progress... | 17|2025| 22 | Python | Work in progress... |

Generated with cgit - Back to sebastiano.tronto.net