Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
min(starmap(point_line_distance, lines)) solution in 3rd party category for Wild Dogs by flpo
from itertools import combinations, starmap
from numpy.linalg import norm
import numpy as np
def point_line_distance(p1, p2, p3=(0, 0)):
return abs(np.cross(p2 - p1, p1 - p3) / norm(p2 - p1))
def max_points(points):
max_length, max_points = 0, []
for p1, p2 in combinations(points, 2):
n_points = sum(point_line_distance(p1, p2, p3) == 0 for p3 in points)
if n_points == max_length:
max_points.append([p1, p2])
elif n_points > max_length:
max_length = n_points
max_points = [[p1, p2]]
return max_points
def wild_dogs(dogs):
lines = max_points([np.array(d) for d in dogs])
return round(min(starmap(point_line_distance, lines)), 2)
Sept. 11, 2018