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

3 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
  2. Thankyou so much for sharing this analysis. I first got confused with some numbers but then when i went through it again i was able to figure it out. You are a genious. I wish ill be able to analyze data the same way some day

    ReplyDelete