Chance of a streak

Medium2D random arraysslicingany with axis· 20 XP

An interviewer asks: "If you flip a fair coin 10 times, what's the chance of getting 3 heads in a row at some point?" The maths is fiddly, so simulate it.

With a generator seeded with 1, make 50,000 rounds of 10 flips with rng.integers(0, 2, size=(50_000, 10)) (1 means heads). Store the share of rounds with at least one run of 3 heads in a row, rounded to 3 decimals.

Expected answer

Store your answer in result.

Hints, the later steps and the answer come with Pro.

import numpy as np

rng = np.random.default_rng(1)
result = ...