![]() A room of computers working at the National Advisory Committee for Aeronautics, 1949. Courtesy of Wikipedia. | "Monte Carlo" simulations are a very powerful technique for calculating values which cannot be calculated exactly. They have been used since the dawn of computing, when scientists on the Manhattan Project were working to design an atomic bomb. Back then, a "computer" was a woman whose job was to do math problems all day long. The nuclear physicists would construct various scenarios of uranium reactions, and then hand these problems off to a room full of computers, similar to a modern data center. Each individual problem didn't explain much about fission, but taking hundreds of scenarios in aggregate allowed the physicists to design the bomb. |
There are four parts of this lab:
Turn in this page for your group
Snarf the code for this lab (or you can browse online).
print_stats
in the module HeadsTails.py.
rc
(an abbreviation for run count): describe its initialization, use, and update.
counts
, specifically, what does counts[k]
represent (in terms of k
)?
In craps if the player rolls a 7 or 11 on the first/come
out roll then you win. If the roll is 2, 3, or 12 then you
lose. If the first roll is something else, a more complicated set
of bets follows. For this problem you should modify the
code in DiceRolling.py so that it
prints two statistics: The
probability that a 7 or 11 is rolled when two dice are rolled and
the probability that 2, 3, or 12 are rolled. Both values should be numbers between 0 and 1.
Do this by creating a new function named craps_simulation
and
calling it at the bottom of the module so that it is the only function
executed when the program runs.
The program to calculate odds is started in Cardtester.py.
get_rank_counts
, is_pair
, and
simulate
to see how the provided code determines how many
hands contain one pair. Run the program a few times and estimate what
percentage of five-card poker hands contain one pair.
is_two_pair
and implement it so that
it returns true if a hand contains exactly two pairs. What's the
body of the function and the probability/odds for two pairs?
You'll need to modify simulate
too.
is_three_of_a_kind
to determine when a
hand has three of a kind exactly (not four of a kind and not a
full house which is three of one rank and two of another
rank). For example, [J,J,J,Q,3] is three of a kind, but
[3,3,3,8,8] is not because it's a full house.
is_fullhouse
and provide both the
code and probability of getting a full house.