Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Wild Dogs by vnkvstnk
from itertools import combinations
def get_parameters(a, b):
d = 1e-6 if (b[0] - a[0]) == 0 else (b[0] - a[0])
slope = (b[1] - a[1]) / d
intercept = a[1] - slope * a[0]
return slope, intercept
def distance(line, a=(0, 0)):
A, C = line
x, y = a
return abs(A*x - y + C)/(A**2 + 1)**.5
def wild_dogs(coords):
combos = combinations(coords, 2)
dist = [distance(get_parameters(*combo)) for combo in combos]
return round(min(dist, key=lambda x: (-dist.count(x), x)), 2)
June 4, 2019
Comments: