File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ from itertools import combinations
2
+
3
+ with open ("input" ) as f :
4
+ inp = f .read ().strip ().split ("\n " )
5
+
6
+
7
+ track = set ()
8
+ for i , l in enumerate (inp ):
9
+ for j , x in enumerate (l ):
10
+ if x != "#" :
11
+ track .add (j + i * 1j )
12
+ if x == "S" :
13
+ start = j + i * 1j
14
+ if x == "E" :
15
+ end = j + i * 1j
16
+
17
+ dirs = [1 , - 1 , 1j , - 1j ]
18
+ times = {start : 0 }
19
+ q = [start ]
20
+ while q :
21
+ p = q .pop ()
22
+ for dp in dirs :
23
+ if p + dp not in track or p + dp in times .keys ():
24
+ continue
25
+ times [p + dp ] = times [p ] + 1
26
+ q .append (p + dp )
27
+
28
+ pt1 , pt2 = 0 , 0
29
+ for p1 , p2 in combinations (times .keys (), 2 ):
30
+ dist = abs (p1 .real - p2 .real ) + abs (p1 .imag - p2 .imag )
31
+ if dist <= 2 :
32
+ pt1 += (times [end ] - (times [p1 ] + times [end ] - times [p2 ] + dist ) >= 100 )
33
+ if dist <= 20 :
34
+ pt2 += (times [end ] - (times [p1 ] + times [end ] - times [p2 ] + dist ) >= 100 )
35
+
36
+ print (pt1 , pt2 )
You can’t perform that action at this time.
0 commit comments