aboutsummaryrefslogtreecommitdiff
path: root/2025/07/b.py
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-12-07 14:28:02 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-12-07 14:28:02 +0100
commit01c2cd358b3f693181fa86e82414b3e32f9a890e (patch)
tree1782399c0d80c4ff5f9fdd225b939806723a7c02 /2025/07/b.py
parenteb233235c876600bafa39a538d18ce11cfc72b39 (diff)
downloadaoc-01c2cd358b3f693181fa86e82414b3e32f9a890e.tar.gz
aoc-01c2cd358b3f693181fa86e82414b3e32f9a890e.zip
Use defaultdict
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