aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-12-07 06:34:41 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-12-07 06:34:41 +0100
commitaa7ddad8c6949b5dfb7a4c77b49c5e65ae5aa782 (patch)
treebcebe015f5764ed45d2c6aa6a22a3b3cf88cb3e3
parentbe683b101393d3566261c9cc10351398bd2e1b6c (diff)
downloadaoc-aa7ddad8c6949b5dfb7a4c77b49c5e65ae5aa782.tar.gz
aoc-aa7ddad8c6949b5dfb7a4c77b49c5e65ae5aa782.zip
Day 7 2025
-rw-r--r--2025/07/a.py17
-rw-r--r--2025/07/b.py15
-rw-r--r--2025/README.md11
-rw-r--r--README.md2
4 files changed, 42 insertions, 3 deletions
diff --git a/2025/07/a.py b/2025/07/a.py
index 5fdb11b..0e13b75 100644
--- a/2025/07/a.py
+++ b/2025/07/a.py
@@ -1,6 +1,19 @@
1import fileinput 1import fileinput
2 2
3with fileinput.input() as lines: 3with fileinput.input() as lines:
4 for line in lines: 4 rows = [line[:-1] for line in lines]
5 ... 5 pos = [rows[0].find('S')]
6 6
7s = 0
8for row in rows[1:]:
9 newpos = set()
10 for p in pos:
11 if row[p] == '^':
12 s += 1
13 newpos.add(p-1)
14 newpos.add(p+1)
15 else:
16 newpos.add(p)
17 pos = list(newpos)
18
19print(s)
diff --git a/2025/07/b.py b/2025/07/b.py
new file mode 100644
index 0000000..41c0db0
--- /dev/null
+++ b/2025/07/b.py
@@ -0,0 +1,15 @@
1import fileinput
2
3with fileinput.input() as lines:
4 rows = [line[:-1] for line in lines]
5 pos = {rows[0].find('S'): 1}
6
7for row in rows[1:]:
8 newpos = {}
9 for p, w in pos.items():
10 for pp in [p-1,p+1] if row[p] == '^' else [p]:
11 t = newpos.get(pp, 0)
12 newpos[pp] = t + w
13 pos = dict(newpos)
14
15print(sum(pos.values()))
diff --git a/2025/README.md b/2025/README.md
index 548deb3..c859ec8 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 7 00:05:27 00:20:40
14 6 00:13:38 01:49:24 15 6 00:13:38 01:49:24
15 5 00:04:39 00:22:19 16 5 00:04:39 00:22:19
16 4 00:25:36 00:27:49 17 4 00:25:36 00:27:49
@@ -85,3 +86,13 @@ smart, very accomplishment.
85 86
86This year so far the only problems that took me more than 30 minutes 87This year so far the only problems that took me more than 30 minutes
87are this and the first one, not exactly the hardest problems imaginable. 88are this and the first one, not exactly the hardest problems imaginable.
89
90### Day 7: Laboratories
91
92This was quite fun! For part 1, I iterate over the rows of the diagram
93keeping a list of the position currently occupied by a tachyon. I use a
94Python set to avoid duplicates. Part 2 is very similar, but the set is
95changed to a map where the keys are the positions and the values are the
96number of multiverses where a tachyon is in that position. To update
97this value for the current row, I sum the values of all tachyons that
98end there from the previous row (that can be one or two tachyons).
diff --git a/README.md b/README.md
index 8b83987..d1ca637 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| 12 | Python | Work in progress... | 17|2025| 14 | Python | Work in progress... |

Generated with cgit - Back to sebastiano.tronto.net