import Data.Ratio main :: IO () main = do print $ dicePosteriors [6] [6] mapM_ (print . map fromRational . flip dicePosteriors [4,6,8,12,20]) [[6], [6,4,8,7,7,2,6], [4,8,7,7,2,6], [6,8,7,7,5,4]] dicePosteriors :: [Integer] -> [Integer] -> [Ratio Integer] dicePosteriors xxs suite = f xxs where f (x:xs) = g (p x [1,1..]) xs where g ys [] = ys g ys (h:t) = g (p h ys) t p x priors = map (/ n) zs where n = sum zs zs = zipWith (*) priors ls ls = map (likelihood x) suite likelihood :: Integer -> Integer -> Ratio Integer likelihood x hypo | hypo < x = 0 | otherwise = 1 % hypo