Last active
March 23, 2016 09:03
-
-
Save jakab922/982a8d065cd5b6eb5eb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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