-
-
Save ryan-mooore/1eca100879ffba5ed44cb87bba98b216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
p = [] | |
s_num = 0 | |
not_visited = [] | |
class Star: | |
def __init__(self, pos): | |
self.x, self.y = pos[0], pos[1] | |
self.neighbors = [] | |
self.closest = 999999999999999999999 | |
def search(self): | |
global not_visited | |
not_visited.remove(self) | |
for n in self.neighbors: | |
if n in not_visited: | |
n.search() | |
while True: | |
s_num += 1 | |
num_stars = int(input()) | |
if num_stars == 0: break | |
s = [] | |
c_num = 0 | |
not_visited = [] | |
for i in range(num_stars): | |
star = Star(input().split(" ")) | |
not_visited.append(star) | |
if len(s) != 0: | |
for o in s: | |
dist = math.sqrt((o.x - star.x)**2 + (o.x - star.x)**2) | |
if dist < star.closest: | |
star.neighbors = [o] | |
star.closest = dist | |
elif dist == star.closest: | |
star.neighbors.append(o) | |
if dist < o.closest: | |
o.neighbors = [star] | |
o.closest = dist | |
elif dist == o.closest: | |
o.neighbors.append(star) | |
while True: | |
if len(not_visited) == 0: | |
break | |
else: | |
not_visited[0].search() | |
c_num += 1 | |
p.append(f"Sky {s_num} contains {c_num} constellations") | |
for h in p: | |
print(h) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment