Chapter 114
Stop the Alien Invasion
A pair of hostile aliens land at two random locations on a spherical planet, each carrying half of a doomsday weapon. They race, at equal speed, to their meeting point, the spot on the surface exactly halfway between them along the shortest path, where they will assemble the weapon. A guardian starts at her own random location on the surface and can stop the attack if she reaches the aliens before they meet. Her speed is times the aliens’. What is the probability she saves the planet?
The Riddler, FiveThirtyEight(original post)
Solution
The first move makes the geometry tractable: because the guardian is faster than the aliens, she wins exactly when she can reach the aliens’ meeting point before they do. If she gets to that rendezvous first, she simply waits or steps toward an arriving alien and catches him; if she cannot, the aliens combine the weapon and it is over. So the race is guardian-to-rendezvous against alien-to-rendezvous.
Work in angles measured from the planet’s centre, with radius and alien speed . Let be the angular separation of the two aliens. Their meeting point sits halfway along the connecting arc, an angular distance from each alien, so an alien reaches after travelling an arc of length , taking time . Let be the angular distance from the guardian’s start to . She moves at , so she reaches after time . The planet is saved when she arrives first:
Now the one fact that does the real work. For two independent points placed uniformly at random on a sphere, the angle between them (as seen from the centre) has probability density This is just the surface area of a thin ring at polar angle : fix the first point as a pole, and the second point’s colatitude has density proportional to , normalised to . Two consequences follow. First, has this density. Second, the meeting point is itself a uniformly random point on the sphere (nothing in its construction prefers any direction), and the guardian is an independent uniform point, so , the angle between guardian and , has the very same density and is independent of .
So and are independent, each with density on , and we want . Integrate over , and for each let run up to , using : The cap at splits the range. For the inner factor is , so that piece is For the inner factor is , giving . Writing and using , that last integral collapses to , so the small- piece is Let and add the two pieces over a common denominator of : The guardian saves the planet about of the time. The same argument with a speed multiplier in place of just moves the split point to ; the lone slow case left is when the aliens land almost on top of each other and the guardian is far away.
The computation
Re-run the scene at random. Drop two aliens and a guardian uniformly on the unit sphere, build the aliens’ meeting point as the normalised average of their positions, and check whether the guardian’s angle to it is less than times the aliens’ separation.
import random, math
random.seed(0)
def rand_sphere():
z = random.uniform(-1, 1)
t = random.uniform(0, 2 * math.pi)
r = math.sqrt(1 - z * z)
return (r * math.cos(t), r * math.sin(t), z)
def angle(a, b):
d = max(-1.0, min(1.0, sum(a[i] * b[i] for i in range(3))))
return math.acos(d)
def saved(k=20):
A, B, G = rand_sphere(), rand_sphere(), rand_sphere()
m = [(A[i] + B[i]) / 2 for i in range(3)]
norm = math.sqrt(sum(c * c for c in m))
if norm < 1e-12: # antipodal aliens, no defined midpoint
return None
M = tuple(c / norm for c in m)
theta, phi = angle(A, B), angle(G, M)
return phi / k < theta / 2 # guardian reaches rendezvous first
trials = [saved() for _ in range(400_000)]
hits = [s for s in trials if s is not None]
print("simulated :", round(sum(hits) / len(hits), 5))
print("formula :", round((149 + 50 * math.cos(math.pi / 10)) / 198, 5))
# simulated : 0.99267
# formula : 0.99269