-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06.py
47 lines (37 loc) · 1.15 KB
/
06.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from lib import *
input = read_input(2018, 6)
width = 0
height = 0
coords = []
for line in input.splitlines():
x, y = map(int, line.split(", "))
coords.append((x, y))
width = max(width, x + 1)
height = max(height, y + 1)
def find_nearest(x, y):
distances = [abs(x - p) + abs(y - q) for p, q in coords]
best_distance = min(distances)
if distances.count(best_distance) > 1:
return None
return distances.index(best_distance)
counter = {}
edge = set()
for y in range(height):
for x in range(width):
nearest = find_nearest(x, y)
if nearest is not None:
counter[nearest] = counter.get(nearest, 0) + 1
if x in (0, width - 1) or y in (0, height - 1):
edge.add(nearest)
print(max(counter[c] for c in counter if c not in edge))
width = 0
height = 0
coords = []
for line in input.splitlines():
x, y = map(int, line.split(", "))
coords.append((x, y))
width = max(width, x + 1)
height = max(height, y + 1)
def measure(x, y):
return sum(abs(x - p) + abs(y - q) for p, q in coords)
print(sum(measure(x, y) < 10000 for x in range(width) for y in range(height)))