pg.73-74: 21. Write a program to simulate the problem described in Exercise 16:

  1. Three points are chosen at random on a circle of unit circumference. What is the probability that the triangle defined by these points as vertices has three acute angles? Hint: One of the angles is obtuse if and only if all three points lie in the same semicircle. Take the circumference as the interval [0, 1]. Take one point at 0 and the others at B and C.

A = c(0,0)
B = c(runif(n=1,min=-1,max=1),runif(n=1,min=-1,max=1))
C = c(runif(n=1,min=-1,max=1),runif(n=1,min=-1,max=1))

Since the first point (point A) is (0,0), in order for all angles to be acute, points B and C should both be in the same quadrant, meaning that both their x and y values should have matching signs (both positive or both negative).

library(data.table)    

# create empty dataframe
matching = data.frame(matches = 0)
matching
##   matches
## 1       0
n = 101

# create a loop where that prints out if coordinates have same sign
for (i in 1:n){
  for (i in length(matching)){
    if((B[1]&C[1]<0 | B[1]&C[1]>0) & (B[2]&C[2]<0 | B[2]&C[2]>0)){
      new = data.frame(matches = 1)
      matching = rbind(matching, new)
      } else {
        new = data.frame(matches = 0)
        matching = rbind(matching, new)
      }
  }
}

# how many out of the runs printed matching (aka 1)
prob = (length(matching$matches== 1)/n-1)*100
prob
## [1] 0.990099