beep
This commit is contained in:
parent
bdeef8224d
commit
e74bd54997
3 changed files with 57 additions and 0 deletions
34
day8/1.py
Normal file
34
day8/1.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import numpy
|
||||
|
||||
with open(r'day8/input.txt', 'r') as input:
|
||||
lines = list(map(lambda x: list(map(lambda y: int(y),x.split(','))),input.read().split('\n')[:-1]))
|
||||
|
||||
def dist(a,b):
|
||||
return (a[0]-b[0])**2 + (a[1]-b[1])**2 + (a[2]-b[2])**2
|
||||
|
||||
def find_best(i, exclusion = []):
|
||||
best_distances[i] = [100000000,-1]
|
||||
for j,node2 in enumerate(lines):
|
||||
print(exclusion)
|
||||
if i == j or j in exclusion: continue
|
||||
distance = dist(node,node2)
|
||||
best_distances[i] = min([distance,j], best_distances[i],key=lambda x : x[0])
|
||||
|
||||
best_distances = []
|
||||
|
||||
idx_circuit = {}
|
||||
|
||||
for i,node in enumerate(lines):
|
||||
idx_circuit[i] = i
|
||||
best_distances.append(0)
|
||||
find_best(i)
|
||||
|
||||
pairs_left = 1000
|
||||
while pairs_left > 0:
|
||||
i = numpy.argmin(best_distances)
|
||||
print(i, best_distances[i])
|
||||
print(idx_circuit)
|
||||
idx_circuit[best_distances[i][1]] = idx_circuit[i]
|
||||
print(idx_circuit.keys())
|
||||
find_best(i, exclusion=filter(lambda x: idx_circuit[x] == idx_circuit[i], idx_circuit.keys()))
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue