Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
first solution in Clear category for Wild Dogs by samatdav02
from itertools import combinations #it can be shorter and faster but i want like this
def equation(pair): #coefficients from the equation y = kx + b
try:
k=round((pair[0][1] - pair[1][1])/(pair[0][0] - pair[1][0]),4)#k coefficient
except: #to avoid situations when dogs are on the same vertical line(DivByZero)
k=0 #(tan does not exist and equation will be x=num)
b=pair[1][1] - k*pair[1][0] #b coefficient
return [k,b]
def wild_dogs(coords):
dogs_pairs=list(combinations(coords,2)) #possible pairs of dogs to build line
equations=[equation(x) for x in dogs_pairs]
dists=sorted([round(abs(line[1])/(line[0]**2+1)**0.5, 2) for line in equations])[::-1]
#^short formula from point to line^
return sorted(dists,key=dists.count)[-1]
July 1, 2019
Comments: