Skip to content

Instantly share code, notes, and snippets.

@blackrobot
Created October 2, 2012 20:01
Show Gist options
  • Save blackrobot/3822936 to your computer and use it in GitHub Desktop.
Save blackrobot/3822936 to your computer and use it in GitHub Desktop.
Best fit algorithm
def distance(points):
OPTIMAL = (75, 75)
x = points[0] - OPTIMAL[0]
y = points[1] - OPTIMAL[1]
return (x ** 2 + y ** 2) ** 0.5
values = [
(12, 88),
(56, 66),
(13, 79),
(69, 60),
(9, 38),
(44, 17),
(82, 42),
(3, 23),
(41, 88),
(45, 37),
]
best = min(values, key=distance)
# >>> print best
# (69, 60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment