In this exercise, we simulate the coupon collector problem. The scenario here is cereal boxes come with one coupon each, and there are 10 unique coupons that may exist in each cereal box for each cereal box. Each of the coupons is equally likely to be in it, but each box only comes with one coupon. And so we're interested in the number of cereal boxes that we must purchase in order to collect all 10 coupons. Yeah, now I've produced some code in our which looks like this. Now I've produced some code in our which looks like this, and the way the code works is I represent the 10 unique coupons with the vector of the numbers one through 10, and then I start off each replication by sampling 10 from the number of coupon. So that represents buying the 1st 10 boxes because we know we need at least 10 boxes in order to collect all 10 coupons. And then I check to see if there exists any coupon that is not in the boxes that we already have. So that is the statement here. It's The statement is true if any of the coupons does not exist in our collection of boxes. So while this is true, we keep sampling one more cereal box where one more coupon and depend that to our list of cereal boxes that we have or the list of coupons that we've accumulated from the cereal boxes. And we simulate this 10,000 times So once. Once this condition is not satisfied, that's when we break the wild group, and that means that we have all 10 coupons. So we run the simulation 10,000 times, and for each replication, we upend the number of cereal boxes that we had to buy in order to collect all 10 coupons for part A were asked the probability of collecting all 10 coupons in the 1st 10 cereal boxes. So if X is the random variable, that is the number of cereal boxes that we had to collect in order to collect all 10 coupons, we're looking for the probability that X is equal to 10, which will be approximately equal to or hopefully approximately equal to our estimate. Where this probability, based on our simulation, the code weaken type in our is as follows. This will give us the probability that we get the all time coupons in the 1st 10 cereal boxes, and the number I got with the simulation was zero point 00 03 That was running it with 10,000 replications. Next for Part B were as to use counting techniques to find the exact probability for part A. So that is the exact probability that we get all 10 coupons in the 1st 10 cereal boxes. Now the probability of an event A is the number of ways to have that event divided by the total number of outcomes or the number of outcomes in the sample space. So for Event A, which is having all 10 coupons in the 1st 10 cereal boxes, there is 10 ways to select the first coupon. The second coupon has to be different. So there is nine ways to select that one eight ways to select the third coupon and so on. So the number of ways to have all different coupons is 10 factorial. That's the number of ways to have all different coupons in 10 cereal boxes and then for the denominated of the total number of ways to have coupons intense cereal boxes. There's 10 coupons that air possibility for the first one 10 that there is a possibility for the second one 10 that are a possibility for the third one and so on. So that number is 10 to the exponents 10 and this comes out to zero point 000 36 three. And so comparing these numbers are simulation did fairly well, but not great. You could increase the accuracy by increasing the number of replications. In this simulation, we're part C. We're asked for the probability that we require more than 20 boxes to collect all 10 coupons. The code that we can use in our is this. And when I run this command, I get a probability of zero point 7857 And lastly for Part D. We're told that on average it takes 29.3 cereal boxes to collect all 10 coupons and were asked to calculate the probability of collecting 0, 10 coupons in less than 29.3 cereal boxes. Since X is an integer value, this is also equal to the probability that it is at most 29. The command in our is this. And for this simulation, this came out to 0.5943