1
+ from collections import defaultdict
2
+
3
+ with open ("input" ) as f :
4
+ inp = f .read ().strip ().split ("\n " )
5
+
6
+ coords = [tuple (map (int , line .split ("," ))) for line in inp ]
7
+
8
+ # Part 1
9
+ minx = min (x for x , _ in coords )
10
+ maxx = max (x for x , _ in coords )
11
+ miny = min (y for _ , y in coords )
12
+ maxy = max (y for _ , y in coords )
13
+
14
+ regions = defaultdict (set )
15
+ for x in range (minx , maxx + 1 ):
16
+ for y in range (miny , maxy + 1 ):
17
+ dists = [(abs (x - cx ) + abs (y - cy ), (cx , cy )) for (cx , cy ) in coords ]
18
+ dists = sorted (dists )
19
+ (d1 , (c1x , c1y )), (d2 , (c2x , c2y )) = dists [0 ], dists [1 ]
20
+ if d1 != d2 :
21
+ regions [(c1x , c1y )].add ((x , y ))
22
+
23
+ corners = []
24
+ left = sorted ([(cx , cy ) for cx , cy in regions .keys () if cx == minx ])
25
+ right = sorted ([(cx , cy ) for cx , cy in regions .keys () if cx == maxx ])
26
+ corners = [left [0 ], left [- 1 ], right [0 ], right [- 1 ]]
27
+
28
+ print (max (len (region ) for c , region in regions .items () if c not in corners ))
29
+
30
+ # Part 2
31
+ total_dist = 10000
32
+
33
+ region = set ()
34
+ for x in range (minx - total_dist // len (coords ), maxx + total_dist // len (coords )):
35
+ for y in range (miny - total_dist // len (coords ), maxy + total_dist // len (coords )):
36
+ if sum (abs (x - cx ) + abs (y - cy ) for cx , cy in coords ) < total_dist :
37
+ region .add ((x , y ))
38
+
39
+ print (len (region ))
0 commit comments