连续两年
先来看看,连续两年都有奖金入账的情况有多常见。
这里我们假设共有 60 名参赛者,前 6 名获得奖金。每位选手用 1 到 60 的编号表示。
本练习是课程的一部分
R 中的概率谜题
练习说明
- 确定在第 1 年和第 2 年都有奖金入账的选手(若有)。
- 检查是否至少有 1 个人在这两年里都有奖金入账。
交互式实操练习
通过完成这段示例代码来试试这个练习。
players <- c(1:60)
count <- 0
for(i in 1:10000){
cash_year1 <- sample(players, 6)
cash_year2 <- sample(players, 6)
# Find those who cashed both years
cash_both <-
# Check whether anyone cashed both years
if(___){
count <- count + 1
}
}
print(count/10000)