Which Urn Did That Ball Come From?
Harlow & Co. runs a prize stall at a games convention. Two urns sit behind the counter, each holding a mix of red and blue tokens. Each visitor spins a wheel that sends them to one urn or the other, draws a single token without looking, and wins a small prize if it is red.
At closing time the attendant finds one red token on the counter and no note of which urn it came out of. Restocking the right urn depends on getting this right, so the manager wants an honest probability rather than a shrug.
The stall is re-set for each convention with different token mixes and a differently weighted wheel, so the four figures - how often the wheel sends a visitor to each urn, and how red each urn is - are what the calculation starts from. Assume the urn was full and exactly one token was drawn.
Task: Print the probability that the red token came from Urn A, as a single number rounded to 4 decimals. Round once, at the end.
Input
Four lines, each a decimal between 0 and 1: the chance the wheel sends a visitor to Urn A, the chance it sends them to Urn B, the share of Urn A's tokens that are red, and the share of Urn B's tokens that are red. The two wheel chances add to 1.
Output
One line holding the probability, rounded to 4 decimals and printed the way Python prints a float - 0.3333.
Example:
Input:
0.5
0.5
0.3
0.6
Output:
0.3333
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in