fork download
  1. import Data.Ratio
  2. main :: IO ()
  3. main =
  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 [] _ = []
  8. dicePosteriors _ [] = []
  9. dicePosteriors suite xs = map (/ sum zs) zs
  10. where
  11. zs = foldr p [1,1..] xs
  12. p x priors = zipWith (*) priors $ map (likelihood x) suite
  13. likelihood :: Integer -> Integer -> Ratio Integer
  14. likelihood x hypo = if hypo < x then 0 else 1 % hypo
  15.  
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]