Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Escape by yuwai
def escape(jar, fly):
W, H, d = jar
x0, y0, vx, vy = fly
def entrance(x,y):
if y==H and (W-d)/20 else -x
dy=H-y if vy >0 else -y
if dx/vxdy/vy:
return x+vx*dy/vy,y+dy,vx,-vy
else :
return x+vx*dy/vy,y+vy*dx/vx,-vx,-vy
# your code here
if vy==0 :
return False
if vx==0:
return (W-d)/2<=x0<=(W+d)/2
i=0 #stamina
while i<20:
x0, y0, vx, vy=intersection(x0, y0, vx, vy)
if not entrance(x0,y0):
i+=1
continue
else :
return True
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 escape([1000, 2000, 200], [20, 35, 100, 175]) == True, "Fifth"
print("Coding complete? Click 'Check' to earn cool rewards!")
Nov. 27, 2019
Comments: