-
Notifications
You must be signed in to change notification settings - Fork 2
/
prob.py
54 lines (33 loc) · 760 Bytes
/
prob.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
#!/usr/bin/env python3
import random
sr = random.SystemRandom()
def sample(prob):
if sr.uniform(0, 1) <= (1 - prob):
return False
return True
def l_not(a):
return not a
def l_and(a, b):
return a and b
def l_or(a, b):
return a or b
def l_xor(a, b):
return l_or(l_and(a, b), l_and(l_not(a), l_not(b)))
def f(a, b, c):
return l_or(l_and(a, b), l_or(l_and(a, c), l_and(b, c)))
def __main__():
count = 1000000 * 10
f_c = 0
f_t = 0
while f_t < count:
ab = sample(0.5)
c = sample(0.8)
b = sample(0.8)
if ab == True:
b = True
if l_and(b, c):
f_c += 1
f_t += 1
print(f_c / f_t)
if __name__ == "__main__":
__main__()