2016/01/13

What's the probability of forming a triangle by breaking a stick twice?

Questions: Supposed that you have 2 chances to break a stick with length of 1 into 3 pieces. What is the probability that the 3 pieces form a triangle?

Code in Python:

[in:]

n=100
y>0
z>0
success = 0
fail = 0
n=1500

for i in range(0,1500):
    x = rd.random()
    y = rd.random()
    if (y>0.5 and x<0.5 and y-x<0.5) or (x>0.5 and y<0.5 and x-y<0.5):
        success = success+1
        
    else:
        fail = fail+1

probability = success/n
print(probability)



[out:]
0.24

2 comments:

  1. Could you please provide information as to some of the numbers you used in your code?

    ReplyDelete
    Replies
    1. Hi. The number used in my code is exactly like above.

      Delete