This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
ProgrammingChallenges/constellation.py

22 lines
466 B
Python
Raw Normal View History

2019-05-02 15:01:00 +00:00
class Star:
def __init__(self, x, y):
self.x = x
self.y = y
def distance_sqr(self, other):
return ((self.x - other.x) ** 2) + ((self.y - other.y) ** 2))
def return_key(A):
return A[2] << 32
def find_constellation(S):
T = []
for i in range(len(S)):
for j in range(i + 1, len(S)):
T.append( (S[i], S[j], S[i].distance_sqr(S[j])) )
T.sort(key=return_key)
cnt = 0
for i in range(len(T)):