## If a stick is broken at random into three pieces, what is the probability ## that the pieces can be put together in a triangle. # counter c = 0 # the number of trials n = 1000 for(i in 1:n) { ## a, b in (0, 1) and a < b v <- sort(runif(2)); ## calculate the length of each edge e <- c(v[1], v[2] - v[1], 1 - v[2]); ## ensure e[1] < e[2] < e[3] e <- sort(e) ## if they can be put together in a triangle if( e[1] + e[2] > e[3] ) { c = c + 1; } } print( c / n )