Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Check all points solution in Clear category for Wild Dogs by GruffGemini
def wild_dogs(coords):
best_lines = []
max_dogs = 0
for i in (range(len(coords) - 1)):
line = equation(coords[i], coords[i + 1])
s = sum(on_line(j, line) for j in coords)
if max_dogs < s:
max_dogs = s
best_lines = [line]
elif max_dogs == s:
best_lines.append(line)
return round(min(distance(line) for line in best_lines), 2)
def equation(p1, p2):
return p1[1] - p2[1], p2[0] - p1[0], p1[0] * p2[1] - p2[0] * p1[1]
def on_line(point, equation):
return not point[0] * equation[0] + point[1] * equation[1] + equation[2]
def distance(line):
return abs(line[2] / (line[0] ** 2 + line[1] ** 2) ** 0.5)
Feb. 21, 2019
Comments: