Time to arrive with dynamic speeds per hour I am writing an algorithm and I have come up against what I think should be a simple problem, but the solution is eluding me.  I'll phrase it in the style of "a train traveling at $x \ \textrm{mph}$" (please forgive me):
The problem
A plane flies at a base rate of $R_b$ over a distance $d$. In a simple world, the amount of time it would take would simply be $\frac{d}{R_b}$. However, I need to account for wind. Wind predictions are available every hour, and for simplicity's sake, we will say that the wind predicted at a certain hour is constant for that entire hour.
The magnitude of the wind ($w$) in the direction of flight has a non-linear affect on $R_b$. For now, let's just say that the rate of flight in hour $i$ ($R_i$), as tempered by the wind, can be given as a function of $R_b$ and $w_i$ (where $w_i$ is the wind for hour $i$ from the weather prediction):
$$R_i = f(R_b, w_i)$$
I need to determine the formula that will tell me when the plane will arrive at its destination.
Thinking through the first few iterations
If we can safely assume that the distance can be traveled in under an hour, it would simply be
$$\frac{d}{R_1}$$
However, if we know that $d$ will certainly take between $1$ and $2$ hours to travel, it would be something like
$$\frac{d - (R_1 \times 1 \ \textrm h)}{R_2} + 1 \ \textrm h$$
Going one step further, assuming it takes between $2$ and $3$ hours
$$\frac{d - (R_1 \times 1 \ \textrm h) - (R_2 \times 1 \ \textrm h)}{R_3} + 2 \ \textrm h$$
And so forth.  (I think that's right?).
Creating a generic formula
How can I write a formula for when I have no idea how long its going to take? Meaning I know all $w_i$ and can dynamically calculate all $R_i$ at the time the function runs, but not before?
 A: Consider the plane's distance travelled as a function of time. This is a piecewise linear function such that
$$d(n) = \sum_{i=1}^n R_i$$
where $n$ is an integer. The inverse of a piecewise linear function is again piecewise linear function, which means if we write it down, it ends up looking something like
$$\mathrm{time}(d) = \begin{cases} \text{expression 1} & \text{plane takes between 0 and 1 hours} \\ \text{expression 2} & \text{plane takes between 1 and 2 hours} \\ \vdots \end{cases}$$
In other words, there's not a super nice way to write this down mathematically that avoids doing the casework you mentioned. That being said, if you had a smoother approximation for intra-hour wind speeds, you might be able to get something nicer.
As far as an algorithm goes, however, this can still be done nicely. I think your algorithm could look something like this (python):
def flight_time(d, Rb, list_of_wind_speeds):
  # i represents the number of hours that have passed
  i = 0
  # keep passing time until the plane has reached its destination
  while d > 0:
    i += 1
    wi = list_of_wind_speeds[i]
    Ri = get_wind_speed(Rb, wi)
    # when the ith hour passes, the plane travels another Ri in distance
    d -= Ri
  return d/Ri + i

In the very last step, the variable d contains the quantity $d-R_1 - R_2 - \cdots - R_i$, where the plane reaches its destination in the $i$th hour. This means that the actual time taken is
$$\frac{d-R_1-R_2-\cdots-R_{i-1}}{R_i} + i-1 = \frac{d - R_1 - R_2 - \cdots - R_i}{R_i} + i$$
and hence we can get our final answer by returning d/Ri + i.
The following may or may not be helpful: to elaborate a bit more on what I mean by "a smoother approximation for intra-hour wind speeds", imagine if we modeled wind speed as a function of time as follows:
$$w(t) = \sum_{i=1}^\infty w_i e^{-(t-i)^2}$$
Then we can compute the function $R(t) = f(R_b, w_i)$, and, as suggested by Eric, the distance travelled by the plane after time $t$ is
$$d(t) = \int_0^t R(t) \, dt$$
Depending on the function $f$, the inverse of this function may be easily computable.
