Premium problem33. Identify the Loaded Coin

Medium Locked

A bag holds fair_coins ordinary coins and double_headed_coins coins with heads on both sides. You draw one coin uniformly at random, flip it n times, and every flip comes up heads. Return the probability that the coin is double-headed.

  • a double-headed coin gives n heads with probability 1
  • a fair coin gives n heads with probability (1/2)n(1/2)^n
  • weight each by how many coins of that kind are in the bag

Input

fair_coins = 999
double_headed_coins = 1
n = 10

Output

0.5061789421651013

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)