-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabouchere.py
63 lines (44 loc) · 1.26 KB
/
labouchere.py
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
53
54
55
56
57
58
59
60
61
62
63
#!user/bin/env python
import random
N = 100000
perc = 0.5
def win(perc):
if random.random() < perc:
return True
else:
return False
def gamble(sequence, balance):
"""Labouchère betting."""
# Won
if len(sequence) < 1:
return balance
# If the sequence is of length 1, the bet is the number in the sequence.
# Otherwise, it is the first number added to the last number.
if len(sequence) == 1:
bet = sequence[0]
else:
bet = sequence[0] + sequence[-1]
# Lost the entire round
if bet > balance:
return balance
won = win(perc)
if won:
return gamble(sequence[1:-1], balance + bet)
else:
return gamble(sequence + [bet], balance - bet)
if __name__ == "__main__":
line1 = [5, 10, 10, 10, 10, 5]
line2 = [5, 5, 10, 10, 10, 5, 5]
line3 = [10, 10, 10, 10, 10]
line4 = [5, 5, 10, 5, 5, 10, 5, 5]
line5 = [2] * 25
line6 = [5] *10
lines = [line1, line2, line3, line4, line5, line6]
final = [0] * len(lines)
starting_balance = 1000
for i in range(N):
for index, line in enumerate(lines):
result = gamble(line, starting_balance)
final[index] += result
avg = [i/N for i in final]
print(avg)