Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Shooting Range by Sim0000
def shot(w1, w2, sp, lp):
f = lambda a, b, c, d: (b[1]-a[1])*(d[0]-c[0]) - (b[0]-a[0])*(d[1]-c[1])
d, n, k = f(sp, lp, w1, w2), f(sp, lp, w1, lp), f(w1, w2, w1, sp)
return round(min(200*n/d, 200-200*n/d))if d and 0<=n/d<=1 and k/d>=0 else -1
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"
Aug. 27, 2014