Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming Assignment 1 In the early 1600s, Galileo was asked to explain the fact that, although 9 can be written as a sum of 3
Programming Assignment 1 In the early 1600s, Galileo was asked to explain the fact that, although 9 can be written as a sum of 3 integers in exactly the same number of ways as 10 can, 9=6+2+1=5+3+1 =4+4+1=5+2+2=4+3+2 =3+3+3 10=6+3+1=5+4+1=6+2+2=5+3+2=4+4+2=4+3+3, when 3 fair dice are rolled, a 9 seemed to come up less often than a 10% supposedly, in the experience of gam- blers. Imagine you are a steampunk Galileo / Galilea. And that some incorrigible gamblers have asked you to confirm and explain why, although, say, 34 can be written as a sum of 10 integers in exactly the same number of ways as 35 can, when 10 dice are rolled, a 34 seems to come up less often than a 35. Answer their and similar questions by writing a computer program (for your steam powered Turing machine) which takes as input a number d of dice and two numbers a, b, and which outputs whether a and b are equally likely to be the sums of a roll of d dice, or if not, which of the two is more likely. Your program should accomplish this by simu- lating the roll of d dice a large number of times and keeping track of the proportion of times the sum is a and the proportion of times it is b. Your program will have to decide (1) how many rolls to perform in order to reach its conclusion with confidence and (2) how close the simulated propor- tions need to be in order to conclude that the actual probabilities are equal. How could it do that? (2) When rolling d fair dice, there are 6d outcomes, each having probability 1/64. So the probability of any event in this sam- ple space is an integer multiple of 1/64. Therefore, if two events do not have the same probability, then their probabilities differ by at least 1/64. (1) We will learn more about this later but for now you may ap- ply the rough rule of thumb that, at least 95% of the time, a simulation of this type with t rolls produces an answer with error less than 1/1t. By combining these ideas you can make your program answer the quiz questions correctly 95% of the time. Submitting Your Work. There are two steps. After writing your program: (1) Complete the associated Canvas quiz, which asks you to run your program for different values of d, a, b. After clicking submit, you will receive instant feedback on whether your answers were correct. If you are unhappy with your score, you can improve your code and then retake the quiz. (The values will change.) (2) After completing the quiz, upload your code to the associated Canvas assign- ment. It will be automatically checked for code similarity against your class- mates'. You must write and submit your own code for this assignment. And begin working on it several days before it is due. Programming Language. You may use any programming language you like to com- plete this assignment. But you are encouraged to use Python and specifically the scientific computing package NumPy. Here are instructions for installing it, and here is a reference for NumPy. The TA's will probably only be able to help you with your code if you use Python. With those installed, a random die roll can be simulated with: import numpy x = numpy.random.randint(1,7) print(x) The first line imports the numpy library. The second line generates a random integer in {1,2,...,6}. The second argument to randint is 7, because according to the documen- tation, randint(a,b) gives a random integer between a (inclusive) and b (exclusive). So, to make sure that we can get a 6 we have to make the second argument 7. The code then prints the result of summing the three die rolls
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started