Skip to content

Instantly share code, notes, and snippets.

@jakab922
Last active March 23, 2016 09:03
Show Gist options
  • Save jakab922/982a8d065cd5b6eb5eb2 to your computer and use it in GitHub Desktop.
Save jakab922/982a8d065cd5b6eb5eb2 to your computer and use it in GitHub Desktop.
import qualified Data.Map as M
import System.Random
import System.Environment
import Control.Monad
insert :: Int -> M.Map Int Int -> [Int] -> M.Map Int Int
insert n m randoms
| n < 1 = m
| otherwise = insert (n - 1) new_map new_randoms
where el = head randoms
new_randoms = tail randoms
new_map = M.insert n el m
main = do
g <- getStdGen
n <- liftM (read . head) getArgs :: IO Int
putStrLn . show . M.size $ insert n M.empty $ randomRs (1, 100) g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment