Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Wild Dogs by Jaime
import math, itertools
def distancias(a,b):
return abs((-a[0]*b[1]+a[0]*a[1])/(b[0]-a[0]) + a[1])/math.sqrt(((a[1]-b[1])/(a[0]-b[0]))**2+(-1)**2)
def alineados(x, y, z):
return (y[0]-x[0])*(z[1]-x[1]) == (y[1]-x[1])*(z[0]-x[0])
def wild_dogs(coords):
doy=[x for x in list(itertools.combinations(coords,3)) if alineados(x[0],x[1],x[2]) ]
if len(doy)>=2: return round(min([distancias(a[0],a[1]) for a in doy]),2)
else: return round(min([distancias(a,b) for a,b in zip(coords,coords[1::])]),2)
if __name__ == '__main__':
print("Example:")
print(wild_dogs([(7, 122), (8, 139), (9, 156),
(10, 173), (11, 190), (-100, 1)]))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert wild_dogs([(7, 122), (8, 139), (9, 156),
(10, 173), (11, 190), (-100, 1)]) == 0.18
assert wild_dogs([(6, -0.5), (3, -5), (1, -20)]) == 3.63
assert wild_dogs([(10, 10), (13, 13), (21, 18)]) == 0
print("Coding complete? Click 'Check' to earn cool rewards!")
Nov. 29, 2019