module NBoys where
import Probability
(Dist, Probability, Trans, Event,
uniform, mapD, sequ, (??), (|||))
data Child = Boy | Girl
deriving (Eq,Ord,Show)
type Family = [Child]
birth :: Trans Family
birth f = uniform [Boy:f,Girl:f]
family :: Int -> Dist Family
family n = sequ (replicate 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) ?? (family n ||| boys k)
numBoys :: Int -> Int -> Dist Int
numBoys n k = mapD countBoys (family n ||| boys k)
onlyBoys1 :: Int -> Probability
onlyBoys1 n = nBoys n 1 n