import Data.Ratio main :: IO () main = mapM_ (print . map fromRational . 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 [] _ = [] dicePosteriors _ [] = [] dicePosteriors suite xs = map (/ sum zs) zs where zs = foldr p [1,1..] xs p x priors = zipWith (*) priors $ map (likelihood x) suite likelihood :: Integer -> Integer -> Ratio Integer likelihood x hypo = if hypo < x then 0 else 1 % hypo