Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in 3rd party category for Wild Dogs by ssk8
from scipy import stats
import numpy as np
from itertools import combinations as combos
def get_lines(pack):
shot_lines, combo_len = [], len(pack)
for combo in [c for i in range(len(pack), 1, -1)for c in combos(pack, i)]:
if shot_lines and combo_len > len(combo):
break
else: combo_len = len(combo)
m, b, r = stats.linregress([[x[y] for x in combo] for y in (0, 1)])[:3]
if r == 1:
shot_lines.append([m, b])
return shot_lines
def get_distances(lines):
dists = []
for line in lines:
m, b = line
x = -b / (m + 1 / m)
y = m * x + b
dists.append(np.sqrt(x*x + y*y))
return [float(format(d, '.2f')) for d in dists]
def wild_dogs(coords):
lines = get_lines(coords)
distances = get_distances(lines)
return min(distances)
Sept. 10, 2018
Comments: