File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ """Solution by treating each splitter individually.
2+
3+ Here, we note that how many beams enter a splitter depends only on the
4+ ones above it, and immediately to its left/right. Moreover, once we find
5+ a splitter directly above a given splitter, we now that we can stop
6+ looking further up that column, since that splitter will block any beams
7+ from higher up.
8+
9+ By noting that no two splitters are ever horizontally adjacent, we can
10+ simplify the iteration logic a good deal.
11+ """
12+
13+ with open ("input" ) as f :
14+ ls = f .read ().strip ().split ("\n " )
15+
16+ splitters = [col for l in ls for col , x in enumerate (l ) if x == "^" ]
17+ entering = [1 ] + [0 ] * (len (splitters ) - 1 )
18+
19+ for i , si in enumerate (splitters ):
20+ for j , sj in enumerate (splitters [:i ][::- 1 ]):
21+ if si == sj :
22+ break
23+ if abs (si - sj ) == 1 :
24+ entering [i ] += entering [i - j - 1 ]
25+
26+ # Part 1
27+ print (sum (b > 0 for b in entering ))
28+
29+ # Part 2
30+ print (sum (entering ) + 1 )
You can’t perform that action at this time.
0 commit comments