Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from random import random
class game:
def __init__(self, initial_stack = 1000):
self.initial_stack = initial_stack
self.money = initial_stack
self.toBet = 1
self.finished = False
def play(self):
win = random() < 18/37
if win:
self.money += self.toBet
if self.money >= self.initial_stack + 50:
self.finished = True
else:
self.money -= self.toBet
self.toBet *=2
if self.toBet > self.money:
self.finished = True
def get_prob_winning(initial_stack, ntries = 100000):
nWin = 0
money = 0
for i in range(ntries):
g = game(initial_stack)
while not g.finished:
g.play()
nWin += (g.money >= initial_stack+50)
money += g.money - initial_stack
return (nWin/ntries,money/ntries)
ww = get_prob_winning(1000)
print("If you play with a 1000€ stack, you loose in {}% of the cases, leading to a {}€ average loss".format(100*(1-ww[0]),-ww[1]))
stack = 0
threshold = .99
for i in reversed(range(0,16)):
stack += 1<<i
prob = get_prob_winning(stack)[0]
print("Stack = {} ---> prob = {} ".format(stack,prob))
if prob >= threshold:
stack -= 1<<i
print("Stack to have {}% chance of winning has to be {}... Suspiciouly close to 32768...".format(100*threshold,stack))
print("You will therefore loose on average {} euros".format(-get_prob_winning(stack)[1]))