Open In Colab

Simulation Assignment

On exam 1, I proposed the problem of having 10 cases of water with 10 bottles in each case and 10 oz in each bottle. One case is known to be filled with one ounce less than all the other bottles. Jacob proposed a random selection method for finding the case with the bottles that have less water. Essentially he’ll pull one bottle and test it. If it is 9 ounces, he has found the case that is short. Let’s explore this random test.

  1. Write a random function call that returns 10 ounces 9 out of 10 times and 9 ounces one out of ten.

  2. What is the expected weight of a random pull?

  3. Test your expected weight by running a simulation drawing at least 100 bottles and taking the average of the wieghts. Does it agree with your theoretical result?

  4. We are particuarly interested in how many pulls would be required to find the case that was short. If you test one at a time, how many pulls do you expect before you find the case that is short?

  5. Create a function that creates a sequence of pulling bottles and stops when you find the bottle with 9 ounces. Test this function a bunch of times. Do you notice anything odd when comparing it to your previous result?

  6. Propose a modification to the coding you did in the first step that would improve the results. Hint: Consider a different data structure that would be more applicable to the real world case.