fork download
  1. import qualified Data.IntMap as I
  2. import Control.Monad
  3. import Data.List
  4. import Data.Maybe
  5. import System.Random
  6.  
  7. main :: IO ()
  8. main = do
  9. rd <- replicateM 100000 rollIkasamaDice
  10. let im = foldr (I.update ((Just $!) . succ)) im0 rd
  11. im0 = I.fromList $ zip [1..4] [0,0..]
  12. print im
  13.  
  14. rollIkasamaDice :: IO Int
  15. rollIkasamaDice = do
  16. d <- getStdRandom (randomR (0, 1)) :: IO Double
  17. let thr = scanl1 (+) $ map . flip (/) =<< sum $ map sqrt [1..4]
  18. a = zip thr [1..] :: [(Double, Int)]
  19.  
  20. return $ snd $ fromJust $ find ((d <=) . fst) a
  21.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.hs:5:8:
    Could not find module `System.Random'
    Use -v to see a list of the files searched for.
stdout
Standard output is empty