Soup Servings
specialist · 790 · lc medium +31 · verified · 59.7% accepted · 1,454 likes · top 58%
Description
Two soups, A and B, each begin with n mL. On every turn, one of four operations is selected uniformly at random (each with probability 0.25):
- serve 100 mL from A and 0 mL from B
- serve 75 mL from A and 25 mL from B
- serve 50 mL from A and 50 mL from B
- serve 25 mL from A and 75 mL from B
Notes:
- There is no operation that serves 0 mL from A and 100 mL from B.
- Both servings happen simultaneously each turn.
- If an operation calls for more soup than remains in a pot, pour everything that is left.
The process ends when either soup is depleted.
Return the probability that A is exhausted first, plus half the probability that both are exhausted simultaneously. Answers within 10-5 of the true answer are accepted.
Example 1:
Example 2:
Code