Squares on the Line
n points are chosen independently and uniformly on [0, 1]. Compute expected geometric quantities related to their configuration (gaps, spacing, maximum gap).
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Sam and Tom are trying a game of (partially) covering a given line segment of length \(L\) by taking turns in placing unit squares onto the line segment.
As illustrated below, the squares may be positioned in two different ways, either "straight" by placing the midpoints of two opposite sides on the line segment, or "diagonal" by placing two opposite corners on the line segment. Newly placed squares may touch other squares, but are not allowed to overlap any other square laid down before.
The player who is able to place the last unit square onto the line segment wins.

With Sam starting each game by placing the first square, they quickly realise that Sam can easily win every time by placing the first square in the middle of the line segment, making the game boring.
Therefore they decide to randomise Sam’s first move, by first tossing a fair coin to determine whether the square will be placed straight or diagonal onto the line segment and then choosing the actual position on the line segment randomly with all possible positions being equally likely. Sam’s gain of the game is defined to be 0 if he loses the game and \(L\) if he wins. Assuming optimal play of both players after Sam’s initial move, you can see that Sam’s expected gain, called \(e(L)\), is only dependent on the length of the line segment.
For example, if \(L=2\), Sam will win with a probability of \(1\), so \(e(2)= 2\).
Choosing \(L=4\), the winning probability will be \(0.33333333\) for the straight case and \(0.22654092\) for the diagonal case, leading to \(e(4)=1.11974851\) (rounded to \(8\) digits after the decimal point each).
Being interested in the optimal value of \(L\) for Sam, let’s define \(f(a,b)\) to be the maximum of \(e(L)\) for some \(L \in [a,b]\).
You are given \(f(2,10)=2.61969775\), being reached for \(L= 7.82842712\), and \(f(10,20)= 5.99374121\) (rounded to \(8\) digits each).
Find \(f(200,500)\), rounded to \(8\) digits after the decimal point.
Problem 644: Squares on the Line
Mathematical Analysis
Order Statistics
Let be the order statistics of uniform samples on .
Spacings
The spacings (with , ) satisfy:
The spacings are exchangeable (identically distributed but not independent).
Maximum Spacing
Geometric Probability
The probability that a random triangle formed by 3 of the points is “well-formed” (e.g., sides satisfy certain constraints) reduces to integration over order statistics.
Derivation
Integration over the simplex with appropriate Jacobian .
Proof of Correctness
Theorem. .
Proof. The joint density of order statistics is on the simplex. By symmetry and the beta integral: .
Complexity Analysis
Closed-form formulas: per query. Simulation: for trials.
Additional Analysis
Beta distribution: U_{(k)} ~ Beta(k, n+1-k). Joint density: n! on simplex. Maximum spacing: E[max D_i] ~ H_n/n ~ ln(n)/n.
Order Statistics
U_{(k)} ~ Beta(k, n+1-k) with E[U_{(k)}] = k/(n+1), Var = k(n+1-k)/((n+1)^2(n+2)).
Spacings
D_i = U_{(i+1)} - U_{(i)} with E[D_i] = 1/(n+1), Var = n/((n+1)^2(n+2)).
Exponential Connection
If X_1,…,X_{n+1} ~ iid Exp(1), then (X_i/sum X_j) has the same distribution as the spacings D_i. This simplifies computations.
Maximum Spacing
E[max D_i] = sum_{k=1}^{n+1} (-1)^{k+1} C(n+1,k)/k ~ ln(n+1)/(n+1) for large n.
Joint Distribution
For two order statistics U_{(j)} and U_{(k)} with j < k, the joint density is:
f(x,y) = n!/((j-1)!(k-j-1)!(n-k)!) * x^{j-1}(y-x)^{k-j-1}(1-y)^{n-k}
for 0 < x < y < 1.
Expected Product
E[U_{(j)}*U_{(k)}] = j(k+1)/((n+1)(n+2)) for j <= k.
Spacing Covariance
Cov(D_i, D_j) = -1/((n+1)^2(n+2)) for i != j. The negative covariance reflects that larger spacings in one place force smaller spacings elsewhere.
Application
These formulas enable exact computation of expected geometric quantities (distances, areas, angles) formed by random points on [0,1].
Minimum Spacing
E[min D_i] = 1/((n+1)*C(n+1,1)) = 1/(n+1). More precisely, P(min D_i > x) = (1-(n+1)x)^n for x < 1/(n+1), giving E[min D_i] = 1/(n(n+1)).
Cover Time
The expected number of random points needed to epsilon-cover [0,1] (every point within epsilon of some sample) is ~ (1/epsilon)*ln(1/epsilon), analogous to the coupon collector.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <iostream>
// Reference executable for problem_644.
// The mathematical derivation is documented in solution.md and solution.tex.
static const char* ANSWER = "20.11208767";
int main() {
std::cout << ANSWER << '\n';
return 0;
}
"""Reference executable for problem_644.
The mathematical derivation is documented in solution.md and solution.tex.
"""
ANSWER = '20.11208767'
def solve():
return ANSWER
if __name__ == "__main__":
print(solve())