続き

main = do
  ht <- new (==) hashInt :: IO (HashTable Int Int)
  gen <- newMTGen Nothing
  mapM_ (trial ht gen) [1..iterateNum]
  xs <- sort <$> H.toList ht
  print $ (fst $ head xs, fst $ last xs, maximumBy (comparing snd) xs)
  where
    trial ht gen _ = do n <- count cardNum <$> (randoms gen :: IO [Double])
                        incr ht n =<< H.lookup ht n
    incr ht k Nothing = H.insert ht k 1
    incr ht k (Just v) = H.update ht k (v + 1) >> return ()