''' lifeguard at the beach problem y distance to swimmer 20, x-distance 30. ratio of speeds 3. ''' import numpy as np, matplotlib.pyplot as plt #plt.interactive(True) s = 3 N = 1000000 d = np.linspace(20,30,N) t = 99. for x in d: prev_t = t t = np.sqrt(x*x+100)/3 + np.sqrt((30-x)**2 + 100) if (t > prev_t): print("found minimum time =",t," at x=",x) break