fork download
  1. import Data.Ratio
  2. main :: IO ()
  3. main = do
  4. mapM_ (print . map fromRational . dicePosteriors [4,6,8,12,20])
  5. [[6], [6,4,8,7,7,2,6], [4,8,7,7,2,6], [6,8,7,7,5,4]]
  6. dicePosteriors :: [Integer] -> [Integer] -> [Ratio Integer]
  7. dicePosteriors suite xxs = f xxs
  8. where
  9. f (x:xs) = let zs = foldr p (p x [1,1..]) xs in map (/ sum zs) zs
  10. f _ = []
  11. p x priors = zipWith (*) priors $ map (likelihood x) suite
  12. likelihood :: Integer -> Integer -> Ratio Integer
  13. likelihood x hypo = if hypo < x then 0 else 1 % hypo
  14.  
Success #stdin #stdout 0s 6320KB
stdin
Standard input is empty
stdout
[0.0,0.39215686274509803,0.29411764705882354,0.19607843137254902,0.11764705882352941]
[0.0,0.0,0.9432484536722126,5.52061280612909e-2,1.5454182664965531e-3]
[0.0,0.0,0.91584527196901,8.040342579700499e-2,3.7513022339850646e-3]
[0.0,0.0,0.91584527196901,8.040342579700499e-2,3.7513022339850646e-3]