Created
January 12, 2015 04:03
-
-
Save amonshiz/723442298e0e0c4e6013 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fac n = product [1..n] | |
combination 0 _ = 1 | |
combination _ 0 = 1 | |
combination n k = | |
let fn = fac n | |
fk = fac k | |
fnk = fac (n - k) | |
in fn / (fk * fnk) | |
bernoulliTrial n k p q = | |
(combination n k) * (p ** k) * (q ** (n - k)) | |
main = do | |
inputs <- getLine | |
let is = (map read $ words inputs) :: [Double] | |
gens = head is | |
num = last is | |
percs = map (\k -> bernoulliTrial (2**gens) k 0.25 0.75) [0..(num - 1)] | |
putStrLn $ show (1 - sum percs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment