BaşlayınÜcretsiz başlayın

Three known values

Now, we will simulate the probability of correctly guessing when the passcode consists of three distinct digits where one of the values is repeated.

Here, suppose that the smudge marks are at the values of 2, 4, and 7. One of these values will be repeated in the passcode, but we do not know which one, nor where the repeated value is within the passcode.

Bu egzersiz, kursun bir parçasıdır

Probability Puzzles in R

Kursa Göz Atın

Egzersiz talimatları

  • Store the three known values into the variable called unique_values.
  • Create an object containing four total values, by choosing one of the unique values at random to be the repeated value and combining it with unique_values, and store it as all_values.
  • Make the guess by choosing at random from the object containing the four values.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

counter <- 0
# Store known values
unique_values <- ___

for(i in 1:10000){
  # Pick repeated value
  all_values <- c(unique_values, ___)
  # Make guess
  guess <- ___
  if(identical(passcode, ___)){
    counter <- counter + 1
  }
}

print(counter / 10000)
Kodu Düzenle ve Çalıştır