Chance That Two Random Lamp Schedules Overlap
Statistics & ExperimentsModel answerLast updated
Two independent events start at uniformly random times in a 30-day window and last 9 and 12 days. Find the probability that their active periods share at least one moment.
Two decorative lamps are switched on at random moments, independently of each other, within the next 30 days.
- The amber lamp is switched on at a time uniformly distributed over the 30-day window. Once on, it stays lit for exactly 9 days.
- The green lamp is switched on at a time uniformly distributed over the same 30-day window. Once on, it stays lit for exactly 12 days.
Only the switch-on times are restricted to the 30-day window. A lamp that is switched on late may remain lit after day 30.
Question: What is the probability that there is at least one moment when both lamps are lit at the same time?
What is expected:
- State your modelling assumptions (continuous time, what is random).
- Turn "the lamps are lit together" into a precise condition on the two start times.
- Compute the exact probability, and explain why your method is valid.
- Briefly describe how you would check the result, and how the answer changes for general window and duration values.
Hints
Hint 1
Let A and G be the two switch-on times. Both are uniform on [0, 30] and independent, so the pair (A, G) is uniform on a square. Probability then becomes a ratio of areas.
Hint 2
Two intervals overlap exactly when each one begins before the other ends. Write this as two inequalities and combine them into a single bound on A - G.
Hint 3
It is easier to compute the complement. The non-overlap region consists of two right triangles in opposite corners of the square. Find their leg lengths from the durations and the window length.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model and assumptions
Let A be the amber switch-on time and G the green switch-on time, measured in days from now.
A ~ Uniform(0, 30)andG ~ Uniform(0, 30), independent.- Amber is lit on
[A, A + 9], green on[G, G + 12]. - Time is continuous. Only the start times are confined to
[0, 30]; the lit periods may extend beyond day 30.
Because the two are independent and uniform, (A, G) is uniformly distributed on the square [0, 30] × [0, 30], which has area 900. Any probability is therefore (area of the favourable region) / 900.
Overlap condition
Two intervals share a point exactly when each starts no later than the other ends:
- Amber starts before green ends:
A < G + 12 - Green starts before amber ends:
G < A + 9
Combined:
-9 < A - G < 12
The window is asymmetric. If green starts first, amber may start up to 12 days later (the length of green's period). If amber starts first, green may start up to 9 days later (the length of amber's period). Each bound is set by the duration of the lamp that starts first.
Computing the area via the complement
Non-overlap happens in exactly two disjoint cases, each a right isosceles triangle in a corner of the square.
Case 1: amber starts at least 12 days after green (A - G >= 12).
Legs have length 30 - 12 = 18. Area = 18² / 2 = 162.
Case 2: green starts at least 9 days after amber (G - A >= 9).
Legs have length 30 - 9 = 21. Area = 21² / 2 = 220.5.
These cases cannot happen together (one needs A - G >= 12, the other A - G <= -9), so the areas add:
non-overlap area = 162 + 220.5 = 382.5
P(no overlap) = 382.5 / 900 = 0.425
P(overlap) = 1 - 0.425 = 0.575 = 23/40
Answer: 23/40 = 0.575.
General formula
For a window of length T and durations a, b (with a, b <= T):
P(overlap) = 1 - ((T - a)² + (T - b)²) / (2T²)
Check: 1 - (21² + 18²) / 1800 = 1 - 765/1800 = 0.575.
If a duration exceeds T, replace T - a by max(T - a, 0), since that triangle disappears.
Sanity checks
- Durations go to 0: the formula gives
1 - 2T²/2T² = 0. Two instantaneous events almost never coincide. - Both durations equal T: the formula gives
1. Any two starts in[0, T]produce overlapping periods. - Magnitude: the combined reach,
9 + 12 = 21days, is a large share of 30, so a value a bit above one half is plausible.
Verification by simulation
import random
def simulate(T=30.0, a=9.0, b=12.0, n=1_000_000, seed=0):
rng = random.Random(seed)
hits = 0
for _ in range(n):
x = rng.uniform(0, T)
y = rng.uniform(0, T)
if x < y + b and y < x + a:
hits += 1
return hits / n
def exact(T=30.0, a=9.0, b=12.0):
return 1 - ((max(T - a, 0)) ** 2 + (max(T - b, 0)) ** 2) / (2 * T ** 2)
Both return about 0.575. The simulation's standard error is roughly sqrt(0.575 * 0.425 / n), about 0.0005 for a million trials. The analytic solution is O(1); the simulation is O(n) time and O(1) space.
Trade-offs and interpretation
- Why the complement: the overlap region is a hexagon, which invites arithmetic slips. The two corner triangles are simpler and easy to verify.
- Boundaries: touching at a single instant corresponds to a line in the square, which has zero area, so
<versus<=does not matter. - Discrete variant: if starts are integer days 1 to 30 and lamps cover whole days (amber on days
A..A+8, green onG..G+11), count lattice points instead. Non-overlapping pairs:(1 + ... + 18) + (1 + ... + 21) = 171 + 231 = 402, soP(overlap) = 498/900 = 83/150 ≈ 0.553. The continuous reading is the natural one, but stating the assumption explicitly is good practice.
Common mistakes
- Using a symmetric condition such as
|A - G| < 9or|A - G| < 12, which ignores the asymmetry. - Swapping the durations in the bounds. Here the two triangle areas simply swap and the total is unchanged, which hides the error, but it would break on variants with different windows per lamp.
- Requiring each lamp to finish by day 30. The problem restricts only start times.
- Forgetting the factor
1/2in a triangle's area, or forgetting to divide by 900. - Computing the overlap region directly instead of the complement, leading to arithmetic errors.