Dice game probabilities: Difference between revisions

m
Line 374:
=={{header|Haskell}}==
{{trans|Python}}
<lang haskell>import Control.Monad (guard, replicateM)
import Data.List (group, sort)
 
Line 387:
 
beatingProbability :: (Int, Int) -> (Int, Int) -> Double
beatingProbability ap1 bp2 = sum $ do
[realToFrac (c1 * c2) / totalOutcomes | (s1, c1) <- counts p1, (s2, c2) <- counts p2, s1 > s2]
(s1, c1) <- counts1
(s2, c2) <- counts2
guard (s1 > s2)
[realToFrac (c1 * c2) / totalOutcomes]
where
counts1counts = uncurry countSums a
counts2totalOutcomes = realToFrac $ uncurry (^) p1 * uncurry countSums(^) bp2
totalOutcomes = realToFrac $ uncurry (^) a * uncurry (^) b
 
main :: IO ()
Anonymous user