Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Wild Dogs by David_Jones
from collections import defaultdict
def wild_dogs(coords):
d = defaultdict(int)
n = len(coords)
for i in range(n - 1):
x1, y1 = coords[i]
for j in range(i + 1, n):
x2, y2 = coords[j]
if x1 == x2:
d['inf', x1] += 1
else:
a, b = (y2 - y1) / (x2 - x1), (x2 * y1 - x1 * y2) / (x2 - x1)
d[a, b] += 1
max_dogs = max(d.values())
distance = min(abs(b) / (1 if a == 'inf' else (a ** 2 + 1) ** .5)
for a, b in d if d[a, b] == max_dogs)
return round(distance, 2) if distance % 1 else int(distance)
May 6, 2019