Problem. A rubber rope is 1 km long. An ant starts at one end and crawls at 1 cm/s toward the other. After every second the rope is stretched uniformly by 1 km (the ant is carried along). Does the ant ever reach the end?
Answer. Yes. Measure progress as the fraction of the rope covered: stretching does not change it, and in second the ant adds . After seconds the fraction is , and the harmonic series diverges, so the ant arrives when , after about seconds (the universe is about s old).
| Model | Fraction covered | Arrival |
|---|---|---|
| discrete: length , after each second, speed | first with the sum | |
| (classic) | first with , | |
| continuous: length , speed | , finite for every | |
| first with , | ratio tends to | |
| rope stretched geometrically (length , ) | converges | may never arrive: needs in the discrete version |
// Ant at speed c on a rope of length a that is stretched uniformly by b after each second.
ll antArrival(double a, double b, double c) { // first n with sum_{k<n} c / (a + k b) >= 1
double f = 0;
for (ll n = 1;; n++) { f += c / (a + (n - 1) * b); if (f >= 1) return n; }
}
ll firstHarmonicAtLeast(long double K) { // smallest n with H_n >= K, for K up to about 30
const long double g = 0.57721566490153286060651209L; // Euler-Mascheroni constant
auto H = [&](ll n) -> long double {
if (n < 64) { long double s = 0; for (ll i = 1; i <= n; i++) s += 1.0L / i; return s; }
long double x = n; return logl(x) + g + 1 / (2 * x) - 1 / (12 * x * x) + 1 / (120 * x * x * x * x);
};
ll lo = 1, hi = 1;
while (H(hi) < K) hi *= 2;
while (lo < hi) { ll mid = lo + (hi - lo) / 2; if (H(mid) >= K) hi = mid; else lo = mid + 1; }
return lo;
}Proof: the fraction argument, divergence and the arrival times
Fraction. Uniform stretching multiplies every distance from the start, the ant’s position and the rope length alike, so the covered fraction is unchanged by stretching. During second (rope length ) the ant adds to . Summing gives the table formula; for it is .
Divergence. For , , so , and diverges (group terms : each group sums to more than ). So eventually exceeds 1 whatever . With , first happens at ; for , .
Continuous. , so , which equals 1 at . Geometric stretching: the increments sum to , so the ant arrives iff this reaches 1, i.e. .
The code.
antArrivalaccumulates exactly the increments.firstHarmonicAtLeastbinary searches with computed directly for small and by the Euler–Maclaurin expansion (error below ) otherwise; is increasing, so the search is valid while the long double error stays below the gap at the answer, which holds for . Checked:antArrivalagainst a step-by-step simulation of positions and lengths,firstHarmonicAtLeastagainst direct summation for .
Related notes
- Harmonic Lemma and Floor Sums
- Jeep Problem (another harmonic-series puzzle)
- Probability and Expectation (coupon collector also gives )