Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Shooting Range by gyahun_dash
import operator as op
def shot(wall1, wall2, shot_point, later_point):
diff = lambda p, q: tuple(map(op.sub, p, q))
prod = lambda p, q: p[0] * q[1] - p[1] * q[0]
wall, direction = diff(wall2, wall1), diff(later_point, shot_point)
det = prod(wall, direction)
if abs(det) < 1e-6: return -1
solve = lambda v: prod(diff(shot_point, wall1), v) / det
rat, fly = map(solve, (direction, wall))
return round(200 * min(rat, 1 - rat)) if 0 <= rat <= 1 and fly > 0 else -1
Aug. 27, 2014