Skip to content

Instantly share code, notes, and snippets.

@amonshiz
Created January 12, 2015 04:03
Show Gist options
  • Save amonshiz/723442298e0e0c4e6013 to your computer and use it in GitHub Desktop.
Save amonshiz/723442298e0e0c4e6013 to your computer and use it in GitHub Desktop.
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