Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Cramer's rule solution in Clear category for Wild Dogs by MrPod
from itertools import combinations
def wild_dogs(coords):
number = set()
for i in combinations(coords, 2):
if i[0][0] == i[1][0]:
k = i[0][0]
b = 0
else:
k = (i[0][1] - i[1][1]) / (i[0][0] - i[1][0])
b = (i[0][0] * i[1][1] - i[0][1] * i[1][0]) / (i[0][0] - i[1][0])
x = (-k * b) / (k**2 + 1)
d = (x**2 + (k * x + b)**2)**.5
number.add((sum(k * j[0] + b == j[1] for j in coords), d))
return round(min(number, key=lambda x: (-x[0], x[1]))[1], 2)
Sept. 11, 2018
Comments: