Soup Servings
You have two soups, A and B, each starting with n mL. On every turn, one of the following four serving operations is chosen at random, each with probability 0.25 independent of all previous turns:
- Pour
100mL from type A and0mL from type B. - Pour
75mL from type A and25mL from type B. - Pour
50mL from type A and50mL from type B. - Pour
25mL from type A and75mL from type B.
Note:
- There is no operation that pours
0mL from A and100mL from B. - The amounts from A and B are poured simultaneously during the turn.
- If an operation asks you to pour more than you have left of a soup, pour all that remains of that soup.
The process stops immediately after any turn in which one of the soups is used up.
Return the probability that A is used up before B, plus half the probability that both soups are used up in the same turn. Answers within 10^-5 of the actual answer will be accepted.
Example 1
Input
n = 50Output
0.625If operations one and two empty A first, operation three empties both at the same time, and operation four empties B first, the result is 0.25 * (1 + 1 + 0.5 + 0) = 0.625.
Example 2
Input
n = 100Output
0.71875Considering all possible serving operations and subsequent operations, the probability of A emptying first plus half the probability of both emptying together is 0.71875.
Constraints
- 0 <= n <= 10^9