module Numeric.Probability.Example.NBoys where
import qualified Numeric.Probability.Distribution as Dist
import Numeric.Probability.Distribution (Event, (??), (?=<<), )
import Numeric.Probability.Example.Boys
(Dist, Probability, Child(Boy), birth, )
import Control.Monad (replicateM)
type Family = [Child]
family :: Int -> Dist Family
family n = replicateM n birth
countBoys :: Family -> Int
countBoys = length . filter (==Boy)
boys :: Int -> Event Family
boys k f = countBoys f >= k
nBoys :: Int -> Int -> Int -> Probability
nBoys n k m = boys m ?? boys k ?=<< family n
numBoys :: Int -> Int -> Dist Int
numBoys n k = Dist.map countBoys (boys k ?=<< family n)
onlyBoys1 :: Int -> Probability
onlyBoys1 n = nBoys n 1 n