【激突】関数型言語 VS オブジェクト指向言語2
■ このスレッドは過去ログ倉庫に格納されています
0799798
2012/05/15(火) 18:50:05.32main = 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 ()
■ このスレッドは過去ログ倉庫に格納されています