From 6f352fd6cc3999bdd9291d5cba8b0d8d559daddf Mon Sep 17 00:00:00 2001 From: tommi27 Date: Thu, 2 May 2019 17:01:00 +0200 Subject: [PATCH] started constellation problem --- constellation.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 constellation.py diff --git a/constellation.py b/constellation.py new file mode 100644 index 0000000..1519451 --- /dev/null +++ b/constellation.py @@ -0,0 +1,21 @@ +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)):