-
-
Save sabeelcoder/db21c98b727328dd3c9b8beca78c7ec7 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
def calculate_distance(p1, p2): | |
return ((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)**0.5 | |
def find_nearest_point(start_point, points): | |
min_distance = math.inf | |
index = 0 | |
for i, point in enumerate(points): | |
distance = calculate_distance(start_point, point) | |
if min_distance > distance: | |
min_distance = distance | |
index = i | |
if points: | |
next_point = points.pop(index) | |
stack.append(next_point) | |
find_nearest_point(next_point, points) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment