Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-100

Polya Urn Expected Red

Problem

A Polya urn starts with r red and b blue balls. Each draw removes a ball and returns it with one extra ball of the same color. Return the expected number of red balls after n draws:

E[R_n] = r + n * r / (r + b).

Return 0.0 when the urn is empty or n < 0.

Hint

The probability the next drawn ball is red stays r / (r + b).

Test cases

case 1
in: [1,1,2]
expected: 2
case 2
in: [2,3,5]
expected: 4
case 3
in: [4,6,0]
expected: 4
case 4
in: [0,5,3]
expected: 0
Starter codePython
def polya_urn_expected_red(r, b, n):
    # Your code here
    pass

4 test cases · run your code against them in the editor