This commit is contained in:
Jack Bond-Preston 2018-12-06 15:41:28 +00:00
parent bf04058082
commit 17692e5d24
2 changed files with 83 additions and 0 deletions

50
aoc-6/inputs.txt Normal file
View 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
View 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 }")