-
Notifications
You must be signed in to change notification settings - Fork 0
/
lia.py
executable file
·45 lines (32 loc) · 967 Bytes
/
lia.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
#! /usr/bin/python3
import sys
import argparse
import signal
from scipy.stats import binom
import numpy as np
import tools
def main(args):
inputs = sys.stdin.read().split()
k, N = list(map(int, inputs))
prob = {
'AA': [1/2, 1/2, 0],
'Aa': [1/4, 1/2, 1/4],
'aa': [0, 1/2, 1/2],
}
# at each generation there is alway the same probability distribution:
# P(AA) = P(aa) = 1/4, P(Aa) = 1/2
#
# thus P(AaBb) = 1/2 * 1/2 = 1/4
def at_least(n, k, p):
return sum((binom(n, p).pmf(i) for i in range(k, n+1)))
print(at_least(2**k, N, 1/4))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='description',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
args = parser.parse_args()
try:
main(args)
except BrokenPipeError:
sys.exit(128 + signal.SIGPIPE)
except KeyboardInterrupt:
sys.exit(128 + signal.SIGINT)