# Use regular expressions to check results sting # Return results into a single string for regular expressions As a hint, the function call random.randint(0, 1) will return a 0 value 50% of the time and a 1 value the other 50% of the time. Put all of this code in a loop that repeats the experiment 10,000 times so we can find out what percentage of the coin flips contains a streak of six heads or tails in a row. Your program breaks up the experiment into two parts: the first part generates a list of randomly selected 'heads' and 'tails' values, and the second part checks if there is a streak in it. Write a program to find out how often a streak of six heads or a streak of six tails comes up in a randomly generated list of heads and tails. Humans are predictably bad at being random. A human will almost never write down a streak of six heads or six tails in a row, even though it is highly likely to happen in truly random coin flips. If you flip a coin 100 times and write down an “H” for each heads and “T” for each tails, you’ll create a list that looks like “T T T T H H H H T T.” If you ask a human to make up 100 random coin flips, you’ll probably end up with alternating head-tail results like “H T H T H H T H T T,” which looks random (to humans), but isn’t mathematically random. Coin Flip Streaksįor this exercise, we’ll try doing an experiment. My code and the question are listed below. My solution was for the first option but I make no distinction between one streak and several. Or are we supposed to find the total number of streaks (6H or 6T) in all samples and divide that by 10,000? My code works fine but my only concern is the phrasing of the task.ĭoes the question want us to find the number of samples (100 flips) that contain at least one streak and divide that by the total number of samples (10,000) ![]() (There can be from $0$ through $16$ coins after $4$ steps, which is all I needed.) The probability of transition from $i$ coins to $j$ coins is $0$ if $j$ is odd and $\right)$.I am attempting to complete the coin flip streaks problem from automate the boring stuff with python. I set this up as a Markov process where the state is the number of coins. I confirmed Michael's answer by the brute-force approach suggested by Calvin and Wim in their answers. This is too long for a reply to my earlier comment, and since it provides an alternate answer, I'm posting it that way. Does anyone have any other ideas, or perhaps a formula to solve this problem? But I'm just not able to calculate how many possible ways exist to get to each amount of total coins by the end. What I've tried to do is to find the total amount of possibilities for each amount of coins by the 5th moment, and then multiply that by the probability that all coins will be vanished on the 5th moment. I've taken a few approaches to this problem. What is the probability that exactly after 5 minutes (that's 5 sets of flips), that the process will have stopped (so no earlier or no later)? Once there are no more coins remaining, the process stops. (Note any new coins are not flipped until the next moment). But for every tails that is flipped, a coin is lost. For each heads that is flipped, you get another coin. At the end of each minute, all coins are flipped simultaneously. ![]() So my friend gave me this question this other day, and I've tried to start it (I'll show my logic below), but I couldn't find any efficient way to do the problem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |