commit aa7ddad8c6949b5dfb7a4c77b49c5e65ae5aa782
parent be683b101393d3566261c9cc10351398bd2e1b6c
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sun, 7 Dec 2025 06:34:41 +0100
Day 7 2025
Diffstat:
4 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/2025/07/a.py b/2025/07/a.py
@@ -1,6 +1,19 @@
import fileinput
with fileinput.input() as lines:
- for line in lines:
- ...
+ rows = [line[:-1] for line in lines]
+ pos = [rows[0].find('S')]
+s = 0
+for row in rows[1:]:
+ newpos = set()
+ for p in pos:
+ if row[p] == '^':
+ s += 1
+ newpos.add(p-1)
+ newpos.add(p+1)
+ else:
+ newpos.add(p)
+ pos = list(newpos)
+
+print(s)
diff --git a/2025/07/b.py b/2025/07/b.py
@@ -0,0 +1,15 @@
+import fileinput
+
+with fileinput.input() as lines:
+ rows = [line[:-1] for line in lines]
+ pos = {rows[0].find('S'): 1}
+
+for row in rows[1:]:
+ newpos = {}
+ for p, w in pos.items():
+ for pp in [p-1,p+1] if row[p] == '^' else [p]:
+ t = newpos.get(pp, 0)
+ newpos[pp] = t + w
+ pos = dict(newpos)
+
+print(sum(pos.values()))
diff --git a/2025/README.md b/2025/README.md
@@ -11,6 +11,7 @@ Example
```
Day -Part 1- -Part 2-
+ 7 00:05:27 00:20:40
6 00:13:38 01:49:24
5 00:04:39 00:22:19
4 00:25:36 00:27:49
@@ -85,3 +86,13 @@ smart, very accomplishment.
This year so far the only problems that took me more than 30 minutes
are this and the first one, not exactly the hardest problems imaginable.
+
+### Day 7: Laboratories
+
+This was quite fun! For part 1, I iterate over the rows of the diagram
+keeping a list of the position currently occupied by a tachyon. I use a
+Python set to avoid duplicates. Part 2 is very similar, but the set is
+changed to a map where the keys are the positions and the values are the
+number of multiverses where a tachyon is in that position. To update
+this value for the current row, I sum the values of all tachyons that
+end there from the previous row (that can be one or two tachyons).
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| 12 | Python | Work in progress... |
+|2025| 14 | Python | Work in progress... |