aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

commit eb233235c876600bafa39a538d18ce11cfc72b39
parent 61718ca8b469ebad7ed59da0ed3c167046cd8e57
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun,  7 Dec 2025 09:14:27 +0100

Clean up and alternative solution to day 7

Diffstat:
M2025/07/a.py | 2+-
M2025/07/b.py | 2+-
A2025/07/b2.py | 17+++++++++++++++++
M2025/README.md | 4++++
4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/2025/07/a.py b/2025/07/a.py @@ -2,9 +2,9 @@ import fileinput with fileinput.input() as lines: rows = [line[:-1] for line in lines] - pos = [rows[0].find('S')] s = 0 +pos = [rows[0].find('S')] for row in rows[1:]: newpos = set() for p in pos: diff --git a/2025/07/b.py b/2025/07/b.py @@ -2,8 +2,8 @@ import fileinput with fileinput.input() as lines: rows = [line[:-1] for line in lines] - pos = {rows[0].find('S'): 1} +pos = {rows[0].find('S'): 1} for row in rows[1:]: newpos = {} for p, w in pos.items(): diff --git a/2025/07/b2.py b/2025/07/b2.py @@ -0,0 +1,17 @@ +import fileinput + +with fileinput.input() as lines: + rows = [line[:-1] for line in lines] + +t = [1 if x == 'S' else 0 for x in rows[0]] +for row in rows[1:]: + next = [0] * len(row) + for i in range(len(row)): + if row[i] == '^': + next[i-1] += t[i] + next[i+1] += t[i] + else: + next[i] += t[i] + t = next + +print(sum(t)) diff --git a/2025/README.md b/2025/README.md @@ -96,3 +96,7 @@ 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). + +I added a second solution for part 2 that does not use a map, but only +lists. This could be seen as a dynamic programming problem where the +iterative implementation is more intuitive than the recursive one.