Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Escape by eugene100372
def escape(jar, fly):
W, H, d = jar
x0, y0, vx, vy = fly
if vy==0: return False
if all((vx==0,x0>(W-d)/2,x0<(W+d)/2)): return True
if vx==0: return False
for i in range(20):
tx,ty = (W*(vx>0)-x0)/vx,(H*(vy>0)-y0)/vy
if tx0,x0>(W-d)/2,x0<(W+d)/2)): return True
y0+=vy*ty
vy=-vy
return False
if __name__ == '__main__':
print("Example:")
print(escape([1000, 1000, 200], [0, 0, 100, 0]))
# These "asserts" are used for self-checking and not for an auto-testing
assert escape([1000, 1000, 200], [0, 0, 100, 0]) == False, "First"
assert escape([1000, 1000, 200], [450, 50, 0, -100]) == True, "Second"
assert escape([1000, 1000, 200], [450, 1000, 100, 0]) == False, "Third"
assert escape([1000, 1000, 200], [250, 250, -10, -50]) == False, "Fourth"
assert abs == True, "Fifth"
print("Coding complete? Click 'Check' to earn cool rewards!")
Nov. 29, 2019
Comments: