Day 6
This commit is contained in:
parent
bf04058082
commit
17692e5d24
50
aoc-6/inputs.txt
Normal file
50
aoc-6/inputs.txt
Normal file
@ -0,0 +1,50 @@
|
||||
336, 308
|
||||
262, 98
|
||||
352, 115
|
||||
225, 205
|
||||
292, 185
|
||||
166, 271
|
||||
251, 67
|
||||
266, 274
|
||||
326, 85
|
||||
191, 256
|
||||
62, 171
|
||||
333, 123
|
||||
160, 131
|
||||
211, 214
|
||||
287, 333
|
||||
231, 288
|
||||
237, 183
|
||||
211, 272
|
||||
116, 153
|
||||
336, 70
|
||||
291, 117
|
||||
156, 105
|
||||
261, 119
|
||||
216, 171
|
||||
59, 343
|
||||
50, 180
|
||||
251, 268
|
||||
169, 258
|
||||
75, 136
|
||||
305, 102
|
||||
154, 327
|
||||
187, 297
|
||||
270, 225
|
||||
190, 185
|
||||
339, 264
|
||||
103, 301
|
||||
90, 92
|
||||
164, 144
|
||||
108, 140
|
||||
189, 211
|
||||
125, 157
|
||||
77, 226
|
||||
177, 168
|
||||
46, 188
|
||||
216, 244
|
||||
346, 348
|
||||
272, 90
|
||||
140, 176
|
||||
109, 324
|
||||
128, 132
|
33
aoc-6/main.py
Normal file
33
aoc-6/main.py
Normal file
@ -0,0 +1,33 @@
|
||||
from collections import defaultdict
|
||||
|
||||
input = open("inputs.txt", "r").read().split('\n')
|
||||
|
||||
coords = [ (int(x.split(',')[0]), int(x.split(',')[1])) for x in input ]
|
||||
|
||||
minCoords = (min(coords, key = lambda x: x[0])[0], min(coords, key = lambda x: x[1])[1])
|
||||
maxCoords = (max(coords, key = lambda x: x[0])[0], max(coords, key = lambda x: x[1])[1])
|
||||
|
||||
areas = defaultdict(int)
|
||||
largerAreas = defaultdict(int)
|
||||
safeArea = 0
|
||||
|
||||
def manhattan_distance(coord1, coord2):
|
||||
return abs(coord1[0] - coord2[0]) + abs(coord1[1] - coord2[1])
|
||||
|
||||
for x in range(minCoords[0] - 1, maxCoords[0] + 2):
|
||||
for y in range(minCoords[1] - 1, maxCoords[1] + 2):
|
||||
closestCoord = min(coords, key = lambda c: manhattan_distance(c, (x, y)))
|
||||
|
||||
distances = sum([ manhattan_distance(c, (x, y)) for c in coords ])
|
||||
if (distances < 10000):
|
||||
safeArea += 1
|
||||
|
||||
largerAreas[closestCoord] += 1
|
||||
|
||||
if (x >= minCoords[0] and x <= maxCoords[0] and y >= minCoords[1] and y <= maxCoords[1]):
|
||||
areas[closestCoord] += 1
|
||||
|
||||
unchangedAreas = { k: v for k, v in areas.items() if v == largerAreas[k] }
|
||||
|
||||
print(f"[Part 1] Largest non-infinite area: { max(unchangedAreas.values()) }")
|
||||
print(f"[Part 2] Safe area: { safeArea }")
|
Loading…
Reference in New Issue
Block a user