Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Wild Dogs by eugene100372
from itertools import*
def l_signature(L):
dx=L[1][0]-L[0][0]
if dx==0: return (abs(L[0][0]))
k=(L[1][1]-L[0][1])/dx
b=L[0][1]-k*L[0][0]
return(L[0][1]-k*L[0][0],abs(b/(k**2+1)**(1/2)))
def wild_dogs(coords):
lines={}
for el in combinations(coords,2):
line = l_signature(el)
if line in lines: lines[line]+=1
else: lines[line]=1
lcmax=0
for line in lines:
if lines[line]>lcmax:
res=line[-1]
lcmax=lines[line]
elif lines[line]==lcmax: res=min(res,line[-1])
if int(res)==res: return res
return round(res,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!")
Sept. 18, 2018
Comments: