शुरू करेंमुफ़्त में शुरू करें

Simulation of a single n

With a room of size 50, let us start by finding a solution via simulation.

In this code, n will represent our room size and match will be our counter for the number of times at least one matching birthday occurred in the simulation, which starts at 0 and should increment in each iteration where a match occurs.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Probability Puzzles in R

पाठ्यक्रम देखें

अभ्यास निर्देश

  • Fill in the required parameters of the sample function, to randomly assign birthdays to each individual.
  • Increment the match variable according to the condition it follows.
  • Calculate the estimated probability of at least one match.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

set.seed(1)
n <- 50
match <- 0

# Simulate 10000 rooms and check for matches in each room
for(i in 1:10000){
  birthdays <- sample(___, ___, replace = ___)
  if(length(unique(birthdays)) < n){
    match <- ___
  } 
}

# Calculate the estimated probability of a match and print it
p_match <- ___
print(___)
कोड संपादित करें और चलाएँ