This repository was archived by the owner on Oct 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday06.py
More file actions
executable file
·65 lines (46 loc) · 1.43 KB
/
Copy pathday06.py
File metadata and controls
executable file
·65 lines (46 loc) · 1.43 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from collections import defaultdict
def dist(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
def uniq_min_idx(data):
uniq = True
idx = 0
for i, val in enumerate(data):
if val < data[idx]:
uniq = True
idx = i
elif val == data[idx]:
uniq = False
return idx if uniq else None
def both():
with open('input') as f:
coords = set()
top = left = float('inf')
bot = right = 0
for line in f:
x, y = map(int, line.split(','))
top = min(top, y)
bot = max(bot, y)
left = min(left, x)
right = max(right, x)
coords.add((x, y))
coords = list(sorted(coords))
not_inf = lambda p: left < p[0] < right and top < p[1] < bot
count = defaultdict(int)
result_2 = 0
for i in range(left, right):
for j in range(top, bot):
distances = [dist((i, j), c) for c in coords]
mn = uniq_min_idx(distances)
if mn is not None:
count[coords[mn]] += 1
if sum(distances) < 10000:
result_2 += 1
result_1 = 0
for point, val in count.items():
if not_inf(point):
result_1 = max(result_1, val)
return result_1, result_2
def main():
print('Both:', *both())
if __name__ == '__main__':
main()