Riddler Classic

This week’s Classic, from Spreck Rosekrans, continues our camping theme. Here are four questions of increasing difficulty about finding sticks in the woods, breaking them and making shapes:

  1. If you break a stick in two places at random, forming three pieces, what is the probability of being able to form a triangle with the pieces?
  2. If you select three sticks, each of random length (between 0 and 1), what is the probability of being able to form a triangle with them?
  3. If you break a stick in two places at random, what is the probability of being able to form an acute triangle — where each angle is less than 90 degrees — with the pieces?
  4. If you select three sticks, each of random length (between 0 and 1), what is the probability of being able to form an acute triangle with the sticks?

In [48]:
import random

In [54]:
N = 1000000

1


In [66]:
triangle_count = 0
for _ in range(N):
    a,b = sorted((random.random(), random.random()))
    x,y,z = (a,b-a,1-b)
    if x<0.5 and y<0.5 and z<0.5:
        triangle_count += 1
        
triangle_count / N


Out[66]:
0.250935

2


In [67]:
triangle_count = 0
for _ in range(N):
    sticks = sorted((random.random(), random.random(), random.random()))
    if sticks[2] < sticks[0] + sticks[1]:
        triangle_count += 1
                    
triangle_count / N


Out[67]:
0.499781

3


In [68]:
triangle_count = 0
for _ in range(N):
    a,b = sorted((random.random(), random.random()))
    x,y,z = (a,b-a,1-b)
    if (x**2 + y**2 >  z**2) and (x**2 + z**2 > y**2) and (z**2 + y**2 > x**2):
        triangle_count += 1
        
triangle_count / N


Out[68]:
0.079496

4


In [69]:
triangle_count = 0
for _ in range(N):
    x,y,z = (random.random(), random.random(), random.random())
    if (x**2 + y**2 >  z**2) and (x**2 + z**2 > y**2) and (z**2 + y**2 > x**2):
        triangle_count += 1
                    
triangle_count / N


Out[69]:
0.21426

In [ ]: