Get startedGet started for free

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.

This exercise is part of the course

Probability Puzzles in R

View Course

Exercise 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 as all_values.
  • Make the guess by choosing at random from the object containing the four values.

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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)
Edit and Run Code