Part 1 2018 Day 25

This commit is contained in:
Luke Hubmayer-Werner 2018-12-26 18:39:01 +10:30
parent 314037e5d6
commit 0bf886b0fe
2 changed files with 1522 additions and 0 deletions

1498
2018/day25-input Normal file

File diff suppressed because it is too large Load Diff

24
2018/day25.py Normal file
View File

@ -0,0 +1,24 @@
with open('day25-input', 'r') as file:
data = [l.strip('\n') for l in file]
import numpy as np
import re
numbers = [[int(s) for s in re.findall(r'-?\d+', d)] for d in data]
arr = np.array(numbers, dtype=np.int64)
max_constellation_radius = 3
constellation_ids = np.arange((len(arr)), dtype=np.int64)
def points_in_range_of(index):
distances = np.abs(arr - arr[index]).sum(axis=1)
return np.argwhere(distances <= max_constellation_radius)[:,0] # Note this will include the point itself
for i in range(len(arr)):
points = points_in_range_of(i)
constellations_to_merge = constellation_ids[points]
constellation_id = constellation_ids[points].min()
for c in constellations_to_merge:
constellation_ids[constellation_ids == c] = constellation_id
print(len(np.unique(constellation_ids))) # Part 1