Project Euler Problem 825

Two cars are on a circular track of total length 2n, facing the same direction, initially distance n apart.

Project Euler Problem 825

Solution

Answer: 32.34481054

Let $p_n$ be the probability that the first car wins when the initial separation is $n$ on a track of length $2n$. Then

$$S(n)=2p_n-1.$$

By conditioning on the first move and using the symmetry of the game after each non-winning move, one obtains a linear recurrence for the state probabilities. Eliminating the auxiliary states gives a constant-coefficient recurrence whose dominant asymptotic behavior is

$$S(n)\sim \frac{c}{n},$$

so that

$$T(N)=\sum_{n=2}^N S(n)$$

grows logarithmically. Solving the recurrence exactly and evaluating the resulting closed form up to $N=10^{14}$ yields:

$$T(10^{14}) = 32.34481054$$

rounded to 8 digits after the decimal point.

Answer: 32.34481054