You will write three functions. The first finds the longest streak in a list of tosses. The second counts the streaks of a given length, and the third simulates the longest streak in tosses.
The idea. Walk along the list and keep a counter of how many equal results you have seen in a row. When the result changes, the counter goes back to . In fair tosses, a streak of or more equal faces is very common.
Your tasks.
longest_run(tosses). Return the length of the longest block of equal results in a row.count_runs(tosses, k). Return how many blocks of equal results are or more long.share_with_run(trials, k). Simulate trials sequences of tosses and return the share that have a run of k or more.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…