All problems
St. Petersburg Finite Cutoff EV
Problem
In the St. Petersburg game a fair coin is flipped until the first tail, paying 2^k after k heads, but play is cut off after n rounds. Each of the n rounds contributes 1 to the expectation, so return [expected payoff, maximum payoff] = [n, 2^n].
Return [0.0, 0.0] for n <= 0.
Hint
The k-th round adds 2^k * 2^(-k) = 1 to the expectation.
Test cases
case 1
in: [1]
expected: [1,2]
case 2
in: [3]
expected: [3,8]
case 3
in: [10]
expected: [10,1024]
case 4
in: [0]
expected: [0,0]
Starter codePython
def st_petersburg_finite_ev(n):
# Your code here
pass4 test cases · run your code against them in the editor