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.
Cet exercice fait partie du cours
Probability Puzzles in R
Instructions
- 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 asall_values
. - Make the guess by choosing at random from the object containing the four values.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
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)