0

Can anyone please explain what each of these two functions do, and what could be a simplified equivalent function to each of them?

def dist(p1, p2):
    return math.sqrt((p1.x - p2.x) *
                     (p1.x - p2.x) +
                     (p1.y - p2.y) *
                     (p1.y - p2.y))

def bruteForce(P, n):
    min_val = float('inf')
    for i in range(n):
        for j in range(i + 1, n):
            if dist(P[i], P[j]) < min_val:
                min_val = dist(P[i], P[j])
 
    return min_val
kezah
  • 13
  • 5
  • The first one is the [euclidean distance](https://www.cuemath.com/euclidean-distance-formula/) between the two points. – Alias Cartellano Mar 04 '22 at 20:56
  • The second one is a brute force approach for finding the pair of points with lowest distance between them. Brute force means trying every possible combination. – Alias Cartellano Mar 04 '22 at 20:58

0 Answers0