LJIWY

Problem 1

\(P(A\ wins\geq 4) = C_6^4 p^4(1-p)^2 + C_6^5p^5(1-p) + C_6^6p^6 = 15p^4(1-p)^2+6p^5(1-p) + p^6\)

get_p = function(x){
  
  p = 15 * x^4 * (1-x)^2 + 6 * x^5 * (1-x) + x^6
  
  # Simulation Approach
  # p = mean(rbinom(10000,6,x)>=4)
  
  return (p)
}

curve(get_p,from = 0,to = 1,
      xlab = "P(A wins a simple game)",
      ylab = "P(A wins 4 out of 6",
      main = "Probability of A winning more than 4 out of 6")

Problem 2

Formulation

Let \(n\) be the number of seats sold, \(X\) be a random variable of people actually showing up. 90% of the people show up is equivalent to each person has a 0.9 probability of showing up. Therefore, \(X\) should follow a Binomial distribution, i.e. \(X~B(n,0.9)\). We want to maximize expected profit, which is:

\(E[Profit] = 10n - E[X-40|X>40]*25 \\\hspace{2cm}= 10n - \sum _{x=41}^n(x-40)P(X=x) \\\hspace{2cm}= 10n - \sum _{x=41}^n(x-40)C_n^x0.9^{x}0.1^{n-x}\)

Therefore, we can formulate it as an optimization problem as follows:

\(max\ 10n - \sum _{x=41}^n(x-40)C_n^x0.9^{x}0.1^{n-x}\)

\(s.t.\)

\(n is integer\)

Solution

p_list = rep(0,30)
for (n in c(41:70)){
  profit = 10*n
  for (x in c(41:n)){
    profit = profit - (x-40)*choose(n,x)*0.9^x*0.1^(n-x)*25
      
    # Simulation approach:
    # profit = profit - (x-40)*mean(rbinom(10000,n,0.9)==x)*25
  }
  p_list[n-40] = profit
  
}

results = data.frame(c(41:70),p_list)

We can see that selling 44 seats will yield the highest expected return.

Problem 3

longest_path = rep(0,10000)
L_on_path = rep(0,10000)

for (t in 1:10000){
  
  ## Simulation set-up
  l=matrix(0,16,16)
  l[1,2]=rtriangle(1, a = 8, b = 16, c = 9)
  l[2,3]=l[2,4]=rtriangle(1, a = 4, b = 12, c = 5)
  l[3,5]=l[3,7]=rtriangle(1, a = 5, b = 7, c = 6)
  l[4,6]=l[4,7]=rtriangle(1, a = 4, b = 16, c = 13)
  l[5,6]=rtriangle(1, a = 3, b = 5, c = 4)
  l[6,8]=l[6,9]=rtriangle(1, a = 2, b = 4, c = 3)
  l[7,10]=rtriangle(1, a = 4, b = 8, c = 6)
  l[8,12]=rtriangle(1, a = 10, b = 18, c = 11)
  l[9,11]=rtriangle(1, a = 3, b = 3, c = 3)
  l[10,13]=rtriangle(1, a = 12, b = 16, c = 14)
  l[11,12]=rtriangle(1, a = 3, b = 5, c = 4)
  l[12,14]=l[12,13]=rtriangle(1, a = 2, b = 4, c = 3)
  l[13,15]=rtriangle(1, a = 8, b = 8, c = 8)
  l[14,15]=rtriangle(1, a = 6, b = 22, c = 11)
  l[15,16]=rtriangle(1, a = 3, b = 6, c = 4)
  
  lanProj<-make.lp(0,16*16)
  
  #set objective coefficients
  set.objfn(lanProj, as.vector(t(l)))

  #set objective direction
  lp.control(lanProj,sense='max')
  
  nodes=c(1:16)
  
  rhs=c(1,rep(0,14),-1)
  for (n in 1:16){
    coef=c(l[n,1:16]/l[n,1:16],-l[1:16,n]/l[1:16,n])
    ind=c((n-1)*16+c(1:16),(c(1:16)-1)*16+n)
    nz=is.finite(coef)
    add.constraint(lanProj,coef[nz], "=",rhs[n],ind[nz])               
  }
  
  ColNames = c()
  RowNames = c()
  for(i in 1:16){
    for(j in 1:16){
      ColNames = cbind(ColNames,paste("x",i,",",j, sep=""))
    }
    RowNames=cbind(RowNames,paste("node",i))
  }
  
  dimnames(lanProj) <- list(RowNames, ColNames)
  set.type(lanProj, c(1:256), "binary")
  
  solve(lanProj)
  
  longest_path[t] = ceiling(get.objective(lanProj)) 
  
  a = l[12,13]
  L_out = which(as.vector(t(l)) %in% a)
  L_on_path[t] = get.variables(lanProj)[L_out[1]] + get.variables(lanProj)[L_out[2]]
  
}

print (ceiling(mean(longest_path)))
## [1] 67
print (mean(L_on_path))
## [1] 0.8701

Problem 4

car=c()
pick=c()
swit=c()

for (s in 1:10000){
  car[s]=sample(33,1)
  pick[s]=sample(33,1)
  
  x=setdiff(c(1:33),union(pick[s],car[s]))
  host=sample(x,5)
  
  swit[s]=sample(setdiff(c(1:33),union(pick[s],host)),1)
}

print(mean(pick==car))
## [1] 0.0294
print(mean(swit==car))
## [1] 0.0356

Problem 5

nsim = 10000

lucky_star = rep(0,nsim)

for (i in 1:nsim){
  pool = 100
  remain = pool
  rv = runif(9)
  
  dist = rep(0,10)
  
  for (n in 1:10){
    if (n == 10){
      dist[n] = remain
    } else {
      dist[n] = remain * rv[n]
      remain = remain - dist[n]
    }
  }
  
  lucky_star[i] = which(dist %in% max(dist))
}

p_lucky_star = rep(0,10)
for (i in 1:10){
  p_lucky_star[i] = sum(lucky_star==i) / nsim
}
print (data.frame(c(1:10),p_lucky_star))
##    c.1.10. p_lucky_star
## 1        1       0.6269
## 2        2       0.2492
## 3        3       0.0861
## 4        4       0.0278
## 5        5       0.0069
## 6        6       0.0025
## 7        7       0.0004
## 8        8       0.0001
## 9        9       0.0000
## 10      10       0.0001