From eb233235c876600bafa39a538d18ce11cfc72b39 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 7 Dec 2025 09:14:27 +0100 Subject: Clean up and alternative solution to day 7 --- 2025/07/a.py | 2 +- 2025/07/b.py | 2 +- 2025/07/b2.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 2025/07/b2.py (limited to '2025/07') diff --git a/2025/07/a.py b/2025/07/a.py index 0e13b75..53ff68c 100644 --- 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 index 41c0db0..4457654 100644 --- 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 new file mode 100644 index 0000000..b77188c --- /dev/null +++ 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)) -- cgit v1.3