15-112 Spring 2012 Homework 9 (Monte Carlo + Tetris)
Due Sunday, 1-Apr, at 10pm

Read these instructions first!


  1. Monte Carlo [10 pts]
    Solve each of the following problems using Monte Carlo techniques (even if you can solve them exactly with math, you must use Monte Carlo techniques here).  For each problem, write a program that, when run, simply prints out the answer as a number between 0 and 1.  Assume a large enough number of trials to get a reasonably accurate answer while still running in a reasonable amount of time (say, less than a few seconds per program).
     
    1. Random Coprimes [5 pts]
      Say that you pick two numbers at random between 2 and 1 billion, inclusive.  In the file randomCoprimes.py, write a program that uses Monte Carlo techniques to compute and print the probability (as a number between 0 and 1) that these two numbers are coprime (that is, that they have no common factors besides 1).
       
    2. Sticky Triangle [5 pts]
      Say that you take a stick and randomly break it in two, then take the longer of the two pieces and randomly break that piece in two, so now you have three pieces.  In the file stickyTriangle.py, write a program that uses Monte Carlo techniques to compute and print the probability (as a number between 0 and 1) that the three pieces can form a triangle.
       
  2. Tetris [90 pts]
    In the file tetris.py, write Tetris exactly according to the design given in this step-by-step tutorial. You may not use a different design, even if you think there's a better way to do it (there probably is, but you still have to do it this way).
     
  3. Tetris Bonus (optional) [up to 10 pts]
    For bonus, you may do some of the additional suggestions on the last page of the tutorial. Submit your bonus in the file bonus-tetris.py, and list all your bonus-worthy changes in a comment at the head of the file.  Note that your tetris.py submission must match the non-bonus spec, and any and all bonus must be exclusively in your bonus-tetris.py file.

carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem