The Three Musketeers in a Semicircle Problem
I came across this interesting problem on which my seniors were brainstorming late at night. It requires a bit knowledge of continuous random variables in probability and little bit visualization capability.
The problem goes like this…
There are three musketeers who stand on a circle randomly, which follows Uniform(0, 2πr) independently where r is the radius of the circle. They can help each other if they are close enough in case of a sudden attack by the enemies. Find the probability of them lying on the same semicircle.
Finally, we have a problem based on continuous random variables. People are often confused how to start approaching problems of this kind where some points are randomly chosen and we have to find probability of these points satisfying a condition. Few general tips that serves as a good starting directions are:
- You don’t care where the first (or first few) random point lies in most cases i.e. often times the position where you place the first (or first few) point doesn’t matter. It is from the second (or some later) point when you have to be careful in order to have a case where the condition is satisfied.
- Condition on what you wished you knew.
- I can’t help but iterate over and over again, Baye’s Rule is really helpful. In this case, it will be the continuous form of Baye’s Rule as we are dealing with continuous random variables.
- Law of Total Probability never goes out of style and is a savior is most cases. Obviously, in this case we will be considering the continuous version.
The last two bullets are more or less standard tools in our toolkit. The first one, you might not find that convincing and the second one might sound bit cryptic. Let’s go through the solution and hopefully you will get some insights.
Let X, Y and Z be i.i.d. Uniform(0, 2πr), which represents our three brave musketeers. Now, notice that wherever X lies it doesn’t matter. It is only when we try to place Y we need to be careful as depending on the placement of Y, the favorable position of Z will be decided.
After placing Y. The above situation arises and Z can lie on the blue region satisfying the condition and on the red region not satisfying the condition. So, I wish we knew about the angle XOY, we could have easily calculate the probability of the three points lying on a semicircle.
But wait a second, I said ‘I wish’.. Hmm, you got it. Let’s leverage the second tip. We condition the required probability on the stuff, we wished we knew. If we are conditioning on something, we have to integrate(since continuous) over all the possible values of that, by Law of Total Probability.
The problem now has reduced considerably to a simpler one. Just one piece of the puzzle needs to be put in place i.e. the probability density of the angle XOY. There is a faster intuitive way to figure out this probability which is restricted to this case of uniform distribution and another slightly rigorous way valid in all situations.
The first way, sprouts from the thinking how you would be placing Y. Since, Y is independent of the position of X and is uniformly distributed. All the angles XOY can take are equally likely or in other words it’s density is constant.
Now, as f is a probability density function. The integral of f over it’s support should be 1.
Before proceeding to the answer, let’s see the other slightly rigorous method to get hold of f. We know,
where F is the cdf of f. It has the following interpretation.
Plugging it in, we get,
Through both way we arrive to the same value of probability density function f. Finally, plugging this density and integrating we get,
Why not verify whether our musketeers are safe or not? Simulation results are presented in the following section.
The code for the python simulation of the above scenario
import random
import math
radius = 1/math.pi # radius of the circle
def isSameSemicircle(): # simulates one random position of 3 points on the circle and tests if they lie on same semicircle
points = [random.uniform(a=0, b=2*math.pi*radius) for _ in range(3)] # place 3 points randomly on the circle
points.sort() # sort the three points
# The following three arc lengths are used to check if the points lie in the same semi-circle
arc_length_1 = points[2] - points[0]
arc_length_2 = 2*math.pi*radius - (points[2] - points[1])
arc_length_3 = 2*math.pi*radius - (points[1] - points[0])
if arc_length_1 <= math.pi*radius:
return 1
else:
if arc_length_2 <= math.pi*radius or arc_length_3 <= math.pi*radius:
return 1
return 0
N = 1000000
print(f"Probability of all three musketeers lying in same semicircle in {N} simulations: {sum([isSameSemicircle() for _ in range(N)]) / N}")
It gives the following output
Probability of all three musketeers lying in same semicircle in 1000000 simulations: 0.749386
Wohoo! Hope you learnt something new from my take on the problem. Definitely reach me out with interesting puzzles. I believe, with our little help, the three musketeers are now more confident to tackle their enemies.