aboutsummaryrefslogtreecommitdiff
path: root/2025/07/b.py
diff options
context:
space:
mode:
Diffstat (limited to '2025/07/b.py')
-rw-r--r--2025/07/b.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/2025/07/b.py b/2025/07/b.py
index 4457654..0a8672e 100644
--- a/2025/07/b.py
+++ b/2025/07/b.py
@@ -1,15 +1,15 @@
1import fileinput 1import fileinput
2from collections import defaultdict
2 3
3with fileinput.input() as lines: 4with fileinput.input() as lines:
4 rows = [line[:-1] for line in lines] 5 rows = [line[:-1] for line in lines]
5 6
6pos = {rows[0].find('S'): 1} 7pos = {rows[0].find('S'): 1}
7for row in rows[1:]: 8for row in rows[1:]:
8 newpos = {} 9 newpos = defaultdict(int)
9 for p, w in pos.items(): 10 for p, w in pos.items():
10 for pp in [p-1,p+1] if row[p] == '^' else [p]: 11 for pp in [p-1,p+1] if row[p] == '^' else [p]:
11 t = newpos.get(pp, 0) 12 newpos[pp] += w
12 newpos[pp] = t + w
13 pos = dict(newpos) 13 pos = dict(newpos)
14 14
15print(sum(pos.values())) 15print(sum(pos.values()))

Generated with cgit - Back to sebastiano.tronto.net