A Train Problem

Published Jul 5, 2022

#math #contests #graphics

A Train

First blog post, mostly messing around with formatting here. This is powered by MDsveX with custom layouts, with plugin support for syntax highlighting and LaTeX\LaTeX.

On an infinitely long track, nn train cars, each with a half chance of containing dynamite, start evenly spaced and all head towards the same direction at distinct constant speeds. When a train AA catches up to another train BB, the front of AA connects to the back of BB to become a longer train. The new train continues moving at the same speed as BB. After a long time has passed (such that no new train connections will take place), the trains halt and are inspected. A train is safe if it has two consecutive train cars not carrying dynamite, otherwise it is dangerous. All dangerous trains are removed from the track due to safety hazards, and the total amount of removed train cars is NN. As nn tends to infinity, E(N)\mathbb{E}(N) converges to some value. Find this value.

— Modified PROMYS 2022 Q10

Solution

The key idea is to consider the slowest train TT. Note that:

  • All trains behind TT will at some point all merge into TT.
  • All trains ahead of TT will never interact with TT or the trains behind it. So, they form their own system with the same conditions in the problem statement.

We can apply a recursion. Define f(x)f(x) to be the probability that a train of length xx (consisting of xx train cars) is dangerous. Note xf(x)xf(x) is the expected value of train cars removed from this train; it’s 0 if it’s not dangerous but xx if it is.

We have

E(n)=1ni=1nif(i)+E(ni)\mathbb{E}(n) = \frac{1}{n}\sum_{i = 1}^{n} i f(i) + \mathbb{E}(n - i)

Here we iterate over all ii, the possible positions of the slowest train, and sum the expected value if(i)+E(ni)i f(i) + \mathbb{E}(n - i) (a train of length ii and a new system with nin - i train cars) in each case, and finally take the average.

We simply the recursion by considering E(n+1)E(n)\mathbb{E}(n + 1) - \mathbb{E}(n):

E(n+1)E(n)=1n+1i=1n+1if(i)+E(n+1i)1ni=1nif(i)+E(ni)\mathbb{E}(n + 1) - \mathbb{E}(n) = \frac{1}{n + 1}\sum_{i = 1}^{n + 1} i f(i) + \mathbb{E}(n + 1 - i) - \frac{1}{n}\sum_{i = 1}^{n} i f(i) + \mathbb{E}(n - i)

Remove the weights,

(n+1)E(n+1)nE(n)=i=1n+1if(i)+E(n+1i)i=1nif(i)+E(ni)(n + 1)\mathbb{E}(n + 1) - n\mathbb{E}(n) = \sum_{i = 1}^{n + 1} i f(i) + \mathbb{E}(n + 1 - i) - \sum_{i = 1}^{n} i f(i) + \mathbb{E}(n - i)
    (n+1)E(n+1)nE(n)=(n+1)f(n+1)+E(n)\iff (n + 1)\mathbb{E}(n + 1) - n\mathbb{E}(n) = (n + 1)f(n + 1) + \mathbb{E}(n)
    E(n+1)=f(n+1)+E(n)\iff \mathbb{E}(n + 1) = f(n + 1) + \mathbb{E}(n)

f(0)=0f(0) = 0, hence

E(n)=i=1nf(n)\mathbb{E}(n) = \sum_{i = 1}^{n} f(n)

Lemma

f(n)=Fn+22nf(n) = \frac{F_{n + 2}}{2^n}, where FiF_i is the ii-th Fibonnaci number.

Note f(n)=g(n)2nf(n) = \frac{g(n)}{2^n}, where g(n)g(n) is the number of possible length nn dangerous trains. Consider the first train car. If it contains dynamite, the entire train is dangerous if and only if the rest (without the first train car) of the train is dangerous. If it doesn’t contain dynamite, the next train car must contain dynamite, and then the rest of the train must be dangerous. g(n)=g(n1)+g(n2)g(n) = g(n - 1) + g(n - 2), and g(1)=2g(1) = 2, g(2)=3g(2) = 3. Thus g(n)=Fn+2g(n) = F_{n + 2}. \blacksquare

It remains to determine

E(n)=i=1nFn+22n\mathbb{E}(n) = \sum_{i = 1}^{n} \frac{F_{n + 2}}{2^n}

Note convergence. Now standard techniques will finish.

E(n)=12i=1nFn+12n1+14i=1nFn2n2\mathbb{E}(n) = \frac{1}{2} \sum_{i = 1}^{n} \frac{F_{n + 1}}{2^{n- 1}} + \frac{1}{4} \sum_{i = 1}^{n} \frac{F_{n}}{2^{n - 2}}
=12i=0n1Fn+22n+14i=1n2Fn+22n= \frac{1}{2} \sum_{i = 0}^{n - 1} \frac{F_{n + 2}}{2^{n}} + \frac{1}{4} \sum_{i = -1}^{n - 2} \frac{F_{n + 2}}{2^{n}}
E(n)=12(E(n)+F21Fn+22n)+14(E(n)+F21+2F1Fn+22nFn+12n1)\mathbb{E}(n) = \frac{1}{2} \left(\mathbb{E}(n) + \frac{F_2}{1} - \frac{F_{n + 2}}{2^n} \right) + \frac{1}{4} \left(\mathbb{E}(n) + \frac{F_2}{1} + 2F_1 - \frac{F_{n + 2}}{2^n} - \frac{F_{n + 1}}{2^{n - 1}} \right)

Solving yields

E(n)=52Fn+3+Fn+22n\mathbb{E}(n) = 5 - \frac{2F_{n + 3} + F_{n + 2}}{2^n}

Then

limnE(n)=5\lim_{n \to \infty} \mathbb{E}(n) = \boxed{5}

Something Else

Here’s a distance estimator for the Sierpenski Pyramid from Syntopia.

// In GLSL, theme is Github Dark 
float pyramidDE(float scale, float offset, int iterations, vec3 p){
    for (int n = 0; n < iterations; ++n) {
        if (p.x + p.y < 0.0){ 
            p.xy = - p.yx;
        } 
        if (p.x + p.z < 0.0){ 
            p.xz = - p.zx;
        } 
        if (p.y + p.z < 0.0){ 
            p.zy = - p.yz;
        } 
        p = p * scale - offset * (scale - 1.0);
    }

    return length(p) * pow(scale, float(-iterations));
}


© 2020-2024 • Last Updated 2024-08-19