Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
a hint of Prim ? solution in Clear category for Connect Stars by rybld2
def dist(x, y): return ((y[0] - x[0]) ** 2 + (y[1] - x[1]) ** 2) ** .5
def connect_stars(coords):
vus, res = [coords[0]], [] # res resultat, vus sommet selectionnés par leur indice dans coords
for _ in range(len(coords) - 1):
d = sorted(((dist(x, y), x, y) for y in coords for x in vus if y not in vus))
res.extend([(coords.index(d[0][1]), coords.index(d[0][2]))])
vus.append(d[0][2])
return res
June 18, 2021
Comments: