-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtempCodeRunnerFile.python
More file actions
41 lines (36 loc) · 1.2 KB
/
tempCodeRunnerFile.python
File metadata and controls
41 lines (36 loc) · 1.2 KB
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
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import random
def func(x, y):
if y > x - 2:
return 1
else:
p_switch = 0
p_stick = 0
correct_doors = [random.randint(1, x) for _ in range(y)]
array = [0] * (x + 1)
for num in correct_doors:
array[num] = 1
wrong_doors = [index for index, value in enumerate(array) if value == 0 and index != 0]
for _ in range(10000):
chosen = random.randint(1, x)
index = random.randint(0, len(wrong_doors) - 1)
opened = wrong_doors[index]
while opened == chosen:
index = random.randint(0, len(wrong_doors) - 1)
opened = wrong_doors[index]
final = random.randint(1, x)
while final == chosen or final == opened:
final = random.randint(1, x)
if array[final] == 1:
p_switch += 1
if array[chosen] == 1:
p_stick += 1
p_switch /= 100
p_stick /= 100
if p_stick == 0:
return 1
return p_switch / p_stick
print(func(50, 15))
print(func(50, 15))