Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Shooting Range by eugene100372
def shot(w1,w2, s, l):
x1,y1,x2,y2,x3,y3=(w1[0]-s[0],w1[1]-s[1],w2[0]-w1[0],w2[1]-w1[1],
l[0]-s[0],l[1]-s[1])
d=x2*y3-x3*y2
if d==0: return -1
k1=(x3*y1-y3*x1)/d
k2=(x2*y1-x1*y2)/d
k1=min(k1,1-k1)
if k1<0 or k2<0: return -1
return round(200*k1)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert shot((2, 2), (5, 7), (11, 2), (8, 3)) == 100, "1st case"
assert shot((2, 2), (5, 7), (11, 2), (7, 2)) == 0, "2nd case"
assert shot((2, 2), (5, 7), (11, 2), (8, 4)) == 29, "3th case"
assert shot((2, 2), (5, 7), (11, 2), (9, 5)) == -1, "4th case"
assert shot((2, 2), (5, 7), (11, 2), (10.5, 3)) == -1, "4th case again"
April 30, 2019