Tuesday 26 May 2020

The Broken Stick Puzzle


Recently I was watching a YouTube video in which a person was investigating the so-called Broken Stick Puzzle using GeoGebra. I realised that it would be interesting to investigate the problem using SageMath, which is what I'll demonstrate in this post. 

However, firstly let's state what this puzzle is about:
Two points are chosen independently and at random on a stick. The stick is broken at those points to form three smaller sticks. What is the probability these three sticks can form a triangle?
My first thought was that the probability would be 0.5 but that turned out to be wrong. Figure 1 shows the variables that I used in my SageMath algorithm, namely pos1, pos2, side1, side2 and side3 for the case where pos1<pos2.

Figure 1

The code runs as follows, in which the variable YES, NO and trials are used as well:
YES,NO=0,0
trials=100000
for i in [1..trials]:
    pos1=RR.random_element(0,1)
    pos2=RR.random_element(0,1)
    side1=min(pos1, pos2)
    side2=abs(pos1-pos2)
    side3=1-(side1+side2)
    if max(side1, side2, side3)>0.5:
        NO+=1
    else:
        YES+=1
print("Relative Frequency of Triangles", n(YES/trials, digits=4))
print("Relative Frequency of non-Triangles", n(NO/trials, digits=4))
 The result, for 100,000 trials, are as follows:
Relative Frequency of Triangles 0.2515
Relative Frequency of non-Triangles 0.7485
Here is the permalink to SageMathCell. Of course, this doesn't prove that the probability of forming a triangle is 0.25. However, it can be shown why the probability is 0.25. This proof is taken from this site:
This altitude theorem can be used to find an answer to a famous probability problem:  If a stick of length x is broken into three pieces, what is the probability that the three pieces can be used to construct a triangle? 
This problem is more difficult than it may originally seem because the sum of the two smaller sides of the triangle must be greater than the third side.  For instance, if the stick is broken into pieces of 2 inches, 3 inches, and 10 inches it will be impossible to construct a triangle. 
Given an equilateral triangle with altitude x, it is possible to use geometry to solve the problem.
 
Any point within the triangle can represent how the stick is broken into three pieces.  For instance, if point P is selected, that represents that the stick is being broken into pieces with length a, b, and c.  By the altitude theorem, it is known that a + b + c = x
In this example it would not be possible to make a triangle, because a + b < c .
To find the probability that the two smaller sides will sum to be larger than the third side it is helpful to divide the equilateral triangle into four smaller equilateral triangles, by connecting the midpoints of the sides.
  
As long as point P is selected in the middle triangle, it will be possible to create a triangle from the three pieces.  (Why?)  The probability that randomly selected P is in the middle triangle is 1/4 so the probability that a triangle can be created from breaking a stick into three pieces is 1/4.
In this proof, the "altitude theorem" referred to is better known as Viviani's Theorem. It's easy to show, using the diagram, that \(s+t+u=h\) where \(h\) is the altitude of the triangle. To do this, suppose the equilateral triangle has a side length of \(a\). Then:$$ \text{Area of Triangle }=\frac{a \times h}{2}=\frac{a \times s}{2}+\frac{a \times t}{2}+\frac{a \times u}{2}$$The 2's and a's cancel out to leave the result of the theorem.

For any interior point P, the sum of the lengths s + u + t
equals the height of the equilateral triangle.

There are variations on this puzzle. Here is one of them taken from this source:
Suppose point A is chosen first, at random, and the stick is broken at this location. Point B is then chosen at random from the longer of the two resulting sticks. What is the probability these three sticks form a triangle? 
Here is the code for this situation (permalink):
YES,NO=0,0
trials=1000000
for i in [1..trials]:
    pos1=RR.random_element(0,1)
    if pos1>0.5:
        pos2=RR.random_element(0, pos1)
        side1=pos2
        side2=pos1-pos2
    else:
        side1=pos1
        pos2=RR.random_element(0,1-pos1)
        side2=pos2
    side3=1-(side1+side2)
    if max(side1, side2, side3)>0.5:
        NO+=1
    else:
        YES+=1
print("Relative Frequency of Triangles", n(YES/trials, digits=4))
print("Relative Frequency of non-Triangles", n(NO/trials, digits=4))
The result, this time for 1,000,000 trials, is as follows:
Relative Frequency of Triangles 0.3865
Relative Frequency of non-Triangles 0.6135
Thus the likelihood of forming a triangle increases because we never break the shorter stick, as was possible in the first instance. At the moment I can't explain the numbers that have been thrown up. Here is the second variant:
Suppose point A is chosen first, at random, and the stick is broken at this location. One of the two resulting sticks is then chosen at random and split at a random location. What is the probability these three sticks form a triangle? This may sound the same as the original problem, but it isn’t!
Here is the algorithm I developed for this situation (permalink). Again it's for a million trials:
YES,NO=0,0
trials=1000000
for i in [1..trials]:
    pos1=RR.random_element(0,1)
    pos2=RR.random_element(0,pos1)
    side1=pos1
    side2=pos2
    side3=1-(side1+side2)
    if max(side1,side2,side3)>0.5:
        NO+=1
    else:
        YES+=1
    pos2=RR.random_element(0,1-pos1)
    side1=pos1
    side2=pos2
    side3=1-(side1+side2)
    if max(side1,side2,side3)>0.5:
        NO+=1
    else:
        YES+=1
YES=int(YES/2)
NO=int(NO/2) 
print("Relative Frequency of Triangles", n(YES/trials, digits=4))
print("Relative Frequency of non-Triangles", n(NO/trials, digits=4)) 
This time the results are:
Relative Frequency of Triangles 0.1730
Relative Frequency of non-Triangles 0.8270
This situation produces the least likelihood of a triangle being formed. After the first break, the shorter of the two pieces can be chosen and broken again but this is futile because the other piece is already greater than 0.5. The longer of the two pieces can also be chosen with equal probability and broken. I can't explain the numbers that have been thrown up. I'll keep investigating.

A much harder question is:
Five points are chosen independently and at a random on a stick. The stick is broken at those points to form six smaller sticks. What is the probability these six sticks can form a tetrahedron?
Here is a recent undergraduate student paper about the topic: link.

No comments:

Post a Comment