開始使用免費開始

連續兩年

先來看看有人連續兩年都有拿到名次獎金的情況有多常見。

在這裡,我們假設只有 60 位參賽者,並對前 6 名頒發獎金。每位玩家以 1 到 60 的數字代表。

本練習屬於課程

R 的機率謎題

檢視課程

練習說明

  • 判斷在第 1 年與第 2 年都有拿到名次獎金的人(若有)的編號。
  • 檢查是否至少有一人在兩年都有拿到名次獎金。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

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)
編輯並執行程式碼