Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Image: ubuntu2004
Coin Flip Simulator
Suppose you flip a fair coin 10 times. What is the probability that you flip at least 4 consecutive tails? Estimate this probability using a simulation.
I declared two empty vectors and .
The vector takes the maximum tail streak length in coin flip by using the coin flip simulation function which was discussed in class.
This is iterated times to get the maximum tail streak length of trials with flips each.
Another sequence iterated from evaluates each maximum tail streak length in . If the maximum tail streak length at is , the vector at is appended to , if the maximum tail streak length , the vector at is appended to .
These series of and values can be interpreted as the results of a series of Bernoulli trails. To find the probability that the maximum tail streak length, take the sum of values in the vector and divide it by the total number of trails .
The probability in each trial varies, but the cumulative probability of a tail streak length greater than or equal to is between to .