ComeçarComece de graça

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.

Este exercício faz parte do curso

Probability Puzzles in R

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

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)
Editar e executar o código