Exercise

Birthday problem

Now we'll use simulation to solve a famous probability puzzle - the birthday problem. It sounds quite straightforward - How many people do you need in a room to ensure at least a 50% chance that two of them share the same birthday?

With 366 people in a 365-day year, we are 100% sure that at least two have the same birthday, but we only need to be 50% sure. Simulation gives us an elegant way of solving this problem.

Upon completion of this exercise, you will begin to understand how to cast problems in a simulation framework.

Instructions 1/2

undefined XP
    1
    2
  • Initialize the sample space days which is an array from 1 to 365.
  • Define a function birthday_sim() that takes one input people and returns the probability that at least two share the same birthday. Set size of draw to number of people.