Settlers of Catan

Teka-teki Probabilitas di R

Peter Chi

Assistant Professor of Statistics Villanova University

Pengenalan permainan

Catan

Teka-teki Probabilitas di R

Mensimulasikan lemparan dadu

roll_dice <- function(k){
  all_rolls <- sample(c(1,2,3,4,5,6), 
                      k, 
                      replace = TRUE)
  final_answer <- sum(all_rolls)
  return(final_answer)
}

roll_dice(2)
7
replicate(10, roll_dice(2))
8 10 10  2 11  5  4  6 11  7
Teka-teki Probabilitas di R

Fungsi table

rolls <- replicate(10, roll_dice(2))
rolls
8 10 10  2 11  5  4  6 11  7
table(rolls)
rolls
2  4  5  6  7  8 10 11 
1  1  1  1  1  1  2  2
Teka-teki Probabilitas di R

Menghitung jumlah kemunculan

rolls <- replicate(100, roll_dice(1))
sum(rolls == 3)
22
if(sum(rolls == 3) > 17) print("The value of 3 was rolled more than 17 times")
"The value of 3 was rolled more than 17 times"
if(sum(rolls == 3) > 17 | sum(rolls == 4) > 17) print("The value of 3 or 4 was rolled more than 17 times")
"The value of 3 or 4 was rolled more than 17 times"
Teka-teki Probabilitas di R

Ayo berlatih!

Teka-teki Probabilitas di R

Preparing Video For Download...