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()))
|
||||||
|
|
||||||
3
day8/2.py
Normal file
3
day8/2.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
with open(r'day8/input.txt', 'r') as input:
|
||||||
|
lines = input.read().split('\n')[:-1]
|
||||||
|
|
||||||
20
day8/input.txt
Normal file
20
day8/input.txt
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
162,817,812
|
||||||
|
57,618,57
|
||||||
|
906,360,560
|
||||||
|
592,479,940
|
||||||
|
352,342,300
|
||||||
|
466,668,158
|
||||||
|
542,29,236
|
||||||
|
431,825,988
|
||||||
|
739,650,466
|
||||||
|
52,470,668
|
||||||
|
216,146,977
|
||||||
|
819,987,18
|
||||||
|
117,168,530
|
||||||
|
805,96,715
|
||||||
|
346,949,466
|
||||||
|
970,615,88
|
||||||
|
941,993,340
|
||||||
|
862,61,35
|
||||||
|
984,92,344
|
||||||
|
425,690,689
|
||||||
Loading…
Add table
Add a link
Reference in a new issue