Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
17 lines (15 sloc) 502 Bytes
import System
import System.Random.Mersenne
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.Bits
import System.TimeIt
main = do
args <- getArgs
let i = read $ head args :: Int
timeIt $ do
gen <- getStdGen
vals <- randoms gen
let m = IntMap.fromList [(x,x) | x <- take i vals] :: IntMap Int
rvals = take i (drop (shiftR i 1) vals)
print (sum [fromIntegral . maybe 0 id $ IntMap.lookup x m | x <- rvals] :: Integer)