Settlers of Catan

Probability Puzzles in R

Peter Chi

Assistant Professor of Statistics Villanova University

Introduction to the game

catan.png

Probability Puzzles in R

Simulating dice rolls

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
Probability Puzzles in R

The table function

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
Probability Puzzles in R

Counting the number of occurrences

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"
Probability Puzzles in R

Let's try it!

Probability Puzzles in R

Preparing Video For Download...