Loops of Ropes
Consider n ropes with 2n ends randomly paired. Let E(n) be the expected number of loops. Find floor(E(10^6)).
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Give a circle $C$ and an integer $n > 1$, we perform the following operations.
In step $0$, we choose two uniformly random points $R_0$ and $B_0$ on $C$.
In step $i$ $\left(1 \leq i < n\right)$, we first choose a uniformly random points $R_i$ on C and connect the points $R_{i-1}$ and $R_i$ with a red rope; then choose a uniformly random point $B_i$ on $C$ and connect the points $B_{i-1}$ and $B_i$ with a blue rope.
In step $n$, we first connect the points $R_{n-1}$ and $R_0$ with a red rope; then connect the points $B_{n-1}$ and $B_0$ with a blue rope.
Each rope is straight between its two end points, and lies above all previous ropes.
After step $n$, we get a loop of red ropes, and a loop of blue ropes.
Sometimes the two loops can be separated, as in the left figure below; sometimes they are "linked", hence cannot be separated, as in the middle and right figures below.

Let $P(n)$ be the probability that the two loops can be separated. For example, $P(3) = \frac{11}{20}$ and $P(5) \approx 0.4304177690$.
Find $P(80)$, rounded to $10$ digit after decimal point.
Problem 807: Loops of Ropes
Mathematical Analysis
By a first-step argument: take one end of rope 1. It pairs with one of ends uniformly at random.
- With probability , it pairs with the other end of rope 1, forming a loop.
- Otherwise, it merges two ropes into one, reducing to effective ropes.
This gives .
Derivation
Unrolling the recurrence with :
This is the sum of reciprocals of odd numbers up to . Equivalently:
where is the harmonic number.
For large : .
Proof of Correctness
The recurrence follows from conditioning on the first pairing. When end 1 of rope 1 pairs with end 2 of rope 1 (probability ), exactly one loop forms and ropes remain. When it pairs with an end of rope (probability ), the two ropes merge and effectively we have ropes with no new loop. The expectation formula telescopes correctly.
Correctness
Theorem. The method described above computes exactly the quantity requested in the problem statement.
Proof. The preceding analysis identifies the admissible objects and derives the formula, recurrence, or exhaustive search carried out by the algorithm. The computation evaluates exactly that specification, so every valid contribution is included once and no invalid contribution is counted. Therefore the returned value is the required answer.
Complexity Analysis
Computing is in exact arithmetic, or using the harmonic number formula with floating-point.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 1000000;
double E = 0.0;
for (int k = 1; k <= n; k++)
E += 1.0 / (2*k - 1);
cout << (long long)E << endl;
return 0;
}
"""
Problem 807: Loops of Ropes
Consider $n$ ropes with $2n$ ends randomly paired. Let $E(n)$ be the expected number of loops. Find $\lfloor E(10^6) \rfloor$.
"""
def solve(n=10**6):
"""Expected number of loops from n ropes."""
E = 0.0
for k in range(1, n + 1):
E += 1.0 / (2 * k - 1)
return int(E)
answer = solve()
print(answer)