fork download
  1. import Data.Ratio
  2.  
  3. main :: IO ()
  4. main = do
  5. print $ dicePosteriors [6] [6]
  6. print $ dicePosteriors [4, 6, 8] [6]
  7. mapM_ (print . map fromRational . dicePosteriors [4,6,8,12,20])
  8. [[6], [6,4,8,7,7,2,6], [4,8,7,7,2,6], [6,8,7,7,5,4]]
  9.  
  10. dicePosteriors :: [Integer] -> [Integer] -> [Ratio Integer]
  11. dicePosteriors suite xxs = f xxs
  12. where
  13. f (x:xs) = g (p x [1,1..]) xs
  14. where
  15. g ys [] = ys
  16. g ys (h:t) = g (p h ys) t
  17. f _ = []
  18. p x priors = map (/ n) zs
  19. where
  20. n = sum zs
  21. zs = zipWith (*) priors ls
  22. ls = map (likelihood x) suite
  23.  
  24. likelihood :: Integer -> Integer -> Ratio Integer
  25. likelihood x hypo
  26. | hypo < x = 0
  27. | otherwise = 1 % hypo
  28.  
Success #stdin #stdout 0s 6280KB
stdin
Standard input is empty
stdout
[1 % 1]
[0 % 1,4 % 7,3 % 7]
[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]