diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-07 06:34:41 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-07 06:34:41 +0100 |
| commit | aa7ddad8c6949b5dfb7a4c77b49c5e65ae5aa782 (patch) | |
| tree | bcebe015f5764ed45d2c6aa6a22a3b3cf88cb3e3 | |
| parent | be683b101393d3566261c9cc10351398bd2e1b6c (diff) | |
| download | aoc-aa7ddad8c6949b5dfb7a4c77b49c5e65ae5aa782.tar.gz aoc-aa7ddad8c6949b5dfb7a4c77b49c5e65ae5aa782.zip | |
Day 7 2025
| -rw-r--r-- | 2025/07/a.py | 17 | ||||
| -rw-r--r-- | 2025/07/b.py | 15 | ||||
| -rw-r--r-- | 2025/README.md | 11 | ||||
| -rw-r--r-- | README.md | 2 |
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 @@ | |||
| 1 | import fileinput | 1 | import fileinput |
| 2 | 2 | ||
| 3 | with fileinput.input() as lines: | 3 | with 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 | ||
| 7 | s = 0 | ||
| 8 | for 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 | |||
| 19 | print(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 @@ | |||
| 1 | import fileinput | ||
| 2 | |||
| 3 | with fileinput.input() as lines: | ||
| 4 | rows = [line[:-1] for line in lines] | ||
| 5 | pos = {rows[0].find('S'): 1} | ||
| 6 | |||
| 7 | for 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 | |||
| 15 | print(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 | ``` |
| 13 | Day -Part 1- -Part 2- | 13 | Day -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 | ||
| 86 | This year so far the only problems that took me more than 30 minutes | 87 | This year so far the only problems that took me more than 30 minutes |
| 87 | are this and the first one, not exactly the hardest problems imaginable. | 88 | are this and the first one, not exactly the hardest problems imaginable. |
| 89 | |||
| 90 | ### Day 7: Laboratories | ||
| 91 | |||
| 92 | This was quite fun! For part 1, I iterate over the rows of the diagram | ||
| 93 | keeping a list of the position currently occupied by a tachyon. I use a | ||
| 94 | Python set to avoid duplicates. Part 2 is very similar, but the set is | ||
| 95 | changed to a map where the keys are the positions and the values are the | ||
| 96 | number of multiverses where a tachyon is in that position. To update | ||
| 97 | this value for the current row, I sum the values of all tachyons that | ||
| 98 | end there from the previous row (that can be one or two tachyons). | ||
| @@ -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... | |
