-
Notifications
You must be signed in to change notification settings - Fork 0
/
q1.py
70 lines (56 loc) · 1.54 KB
/
q1.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
64
65
66
67
# coding: utf-8
# In[1]:
import numpy as np
import heapq as hq
np.random.seed(0)
# In[2]:
T = 8
N = 2
maxReg = np.array([0, 0])
lastReg = np.array([0, 0])
M = np.zeros(T)
L = np.zeros(T)
for ii in np.arange(0, T):
num = np.random.randint(1, 10, 1)
if lastReg[-2] == 0:
lastReg[-1] = num
lastReg[-2] = lastReg[-1]
lastReg[-1] = num
if num > np.min(maxReg):
maxReg[maxReg == np.min(maxReg)] = num
M[ii] = np.prod(maxReg)
L[ii] = np.prod(lastReg)
diffML = M - L
print("Mean of M - L: ", np.mean(diffML))
print("Standard deviation of M - L: ", np.std(diffML))
a = 32
b = 64
p_diffML_in_ab = len(diffML[(diffML>=a) * (diffML<=b)])/len(diffML)
p_diffML_leq_b = len(diffML[diffML<=b])/len(diffML)
print("Probability that M - L >= a given M - L <= b: ", p_diffML_in_ab/p_diffML_leq_b)
# In[3]:
T = 32
N = 4
maxReg = np.zeros(N)
lastReg = np.zeros(N)
M = np.zeros(T)
L = np.zeros(T)
for ii in np.arange(0, T):
num = np.random.randint(1, 10, 1)
if lastReg[0] == 0:
lastReg[:] = num
lastReg[-2] = lastReg[-1]
lastReg[-1] = num
if num > np.min(maxReg):
maxReg[maxReg == np.min(maxReg)] = num
M[ii] = np.prod(maxReg)
L[ii] = np.prod(lastReg)
diffML = M - L
print("Mean of M - L: ", np.mean(diffML))
print("Standard deviation of M - L: ", np.std(diffML))
a = 2048
b = 4096
p_diffML_in_ab = len(diffML[(diffML>=a) * (diffML<=b)])/len(diffML)
p_diffML_leq_b = len(diffML[diffML<=b])/len(diffML)
print("Probability that M - L >= a given M - L <= b: ", p_diffML_in_ab/p_diffML_leq_b)
# In[ ]: