You have n fair coins and you flip them all at the same time. Any that come up tails you set aside. The ones that come up heads you flip again. How many rounds do you expect to play before only one coin remains?
Write a function that, given n, returns the number of rounds you’d expect to play until one coin remains.
In each round of flipping the coins, about half of the coins will come up heads (since each flip is an independent event with a 50% chance). We can estimate the number of rounds required to reduce n coins to one remaining coin by repeatedly reducing the number of coins by half.
Mathematical Insight: In each round, the number of remaining coins is expected to halve.
Number of Rounds: This process continues until only one coin remains. The number of rounds required to reduce n to 1 can be estimated using the logarithm base 2 of n.
Return Value: For an integer n, the expected number of rounds required is the ceiling value of the logarithm base 2 of n.