-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiprb.hs
More file actions
47 lines (40 loc) · 1.38 KB
/
Copy pathiprb.hs
File metadata and controls
47 lines (40 loc) · 1.38 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
42
43
44
45
46
47
{-
Given: Three positive integers k, m, and n,
representing a population containing k+m+n organisms:
k individuals are homozygous dominant for a factor,
m are heterozygous, and n are homozygous recessive.
Return: The probability that two randomly selected
mating organisms will produce an individual possessing
a dominant allele (and thus displaying the dominant phenotype).
Assume that any two organisms can mate.
-}
{-
example: 2 2 2
2 homozygous dominant (AA), 2 heterozygous (Aa), and 2 homozygous recessive (aa)
P(dominant) = (P(AA + AA) + P(AA + Aa) + P(Aa + Aa) + P(Aa + aa) + P(AA + aa)) / C(6,2)
= (1 + 4 + 1 * 0.75 + 4 * 0.5 + 4) / (6! / 2! * 4!)
= 0.78333
-}
-- fast check if length of list <=n
fastCheck n = null . drop n
factorial n = product [1..n]
c n k = factorial n / ((factorial k) * (factorial (n - k)))
prob k m n = p
where
s = [
k * (k - 1), --AA, AA
k * m, --AA, Aa
k * n, --AA, aa
m * k, --Aa, AA
m * (m - 1) * 0.75, --Aa, Aa
m * n * 0.5, --Aa, aa
n * k, --aa, AA
n * m * 0.5 --aa, Aa
]
f = k + m + n
p = sum s / (f * (f - 1))
main = do
input <- readFile "rosalind_iprb.txt"
let
(k:m:n:xs) = words input
print $ prob (read k) (read m) (read n)