Skip to content

Instantly share code, notes, and snippets.

@talhaahussain
Created June 13, 2024 02:09
Show Gist options
  • Save talhaahussain/65fe3193964921228cdf97d1788afac8 to your computer and use it in GitHub Desktop.
Save talhaahussain/65fe3193964921228cdf97d1788afac8 to your computer and use it in GitHub Desktop.
euclidean_distance.py -- A Python program for computing the line segment length between two n-dimensional points in Euclidean space, using Cartesian coordinates and the Pythagorean theorem, where each point is represented as a list of n length.
import math
def distance(a: list[int], b: list[int]) -> list[int]:
assert len(a) == len(b), "Coordinates must be in same dimension."
return math.sqrt(sum([(a[i] - b[i])**2 for i in range(len(a))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment