All problems
Martingale Betting Expected Profit
Problem
A martingale betting system bets base_bet and doubles after each loss for up to max_bets bets. A win at any point nets base_bet; losing every bet loses base_bet * (2^max_bets - 1). Return the expected profit:
E = base_bet * (1 - (1 - p)^max_bets) - base_bet * (2^max_bets - 1) * (1 - p)^max_bets.
Return 0.0 for max_bets <= 0.
Hint
For a fair game the expected profit stays exactly zero.
Test cases
case 1
in: [1,0.5,3]
expected: 0
case 2
in: [1,0.5,5]
expected: 0
case 3
in: [1,0.4,3]
expected: -0.7279999999999998
case 4
in: [10,0.5,2]
expected: 0
Starter codePython
def martingale_expected_profit(base_bet, p, max_bets):
# Your code here
pass4 test cases · run your code against them in the editor