Created
October 2, 2012 20:01
-
-
Save blackrobot/3822936 to your computer and use it in GitHub Desktop.
Best fit algorithm
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 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