{-# LANGUAGE BangPatterns #-}
import qualified Data.IntMap.Lazy as I
import System.Random
main = do
(a, b) <- dicePi 4 1000000
dicePi diceNum n = do
(r
, d
) <- go n
0 (I
.fromList
$ zip [1..6] [0,0..]) return (4 * r
/ n
, I
.assocs d
) where
go
0 count d
= return (count
, d
) go m count d = do
x0 <- replicateM diceNum rollDice
y0 <- replicateM diceNum rollDice
!x = f x0
!y = f y0
d' = foldr upd d $ x0 ++ y0
go (m - 1) (if h < 1.0 then count + 1 else count) d'
where
g [] = 0
g (x:xs) = x - 1 + 6 * (g xs)
upd k im
= I
.update
((Just
$!) . succ) k im
rollDice = getStdRandom (randomR (1, 6))
ey0jIExBTkdVQUdFIEJhbmdQYXR0ZXJucyAjLX0KaW1wb3J0IHF1YWxpZmllZCBEYXRhLkludE1hcC5MYXp5IGFzIEkKaW1wb3J0IENvbnRyb2wuTW9uYWQKaW1wb3J0IFN5c3RlbS5SYW5kb20KCm1haW4gOjogSU8gKCkKbWFpbiA9IGRvCiAgKGEsIGIpIDwtIGRpY2VQaSA0IDEwMDAwMDAKICBwdXRTdHJMbiAkICJwaSA9ICIgKysgc2hvdyBhCiAgcHJpbnQgYgoKZGljZVBpIDo6IEludCAtPiBEb3VibGUgLT4gSU8gKERvdWJsZSwgWyhJbnQsIEludCldKQpkaWNlUGkgZGljZU51bSBuID0gZG8KICAociwgZCkgPC0gZ28gbiAwIChJLmZyb21MaXN0ICQgemlwIFsxLi42XSBbMCwwLi5dKQogIHJldHVybiAoNCAqIHIgLyBuLCBJLmFzc29jcyBkKQogIHdoZXJlCiAgICBnbyAwIGNvdW50IGQgPSByZXR1cm4gKGNvdW50LCBkKQogICAgZ28gbSBjb3VudCBkID0gZG8KICAgICAgeDAgPC0gcmVwbGljYXRlTSBkaWNlTnVtIHJvbGxEaWNlCiAgICAgIHkwIDwtIHJlcGxpY2F0ZU0gZGljZU51bSByb2xsRGljZQogICAgICBsZXQgIWggPSAoc3FydCAkISB4ICogeCArIHkgKiB5KSA6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