The Problem: Given 3 inputs Bounce, Ball drop height, and ball view height.
How do I calculate the number of times the observer can see the ball pass. So my code gives correct output, but it takes a longer time as bounce approaches 1, how do I make it deterministic in nature.
def bouncingBall(h, bounce, window): BounceFactor = bounce BallDropHeight = h ViewerHeight = window BounceLeft = h BallSeenTimes = 1 if bounce > 1 or bounce < 0 or window >= h or h ==0: return -1 else: while (BounceLeft > ViewerHeight): BounceLeft = BounceLeft * BounceFactor if (BounceLeft > ViewerHeight): BallSeenTimes = BallSeenTimes + 2 else: break return BallSeenTimes
I am not looking for code answers, just the direction in which I need to think. Currently, I think If I could somehow establish a linear relationship and create a function to "guess" the passes it would be faster.