Skip to content

Instantly share code, notes, and snippets.

@sphynx
Created March 25, 2015 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sphynx/ba48d74c854dd7bb2a7a to your computer and use it in GitHub Desktop.
Save sphynx/ba48d74c854dd7bb2a7a to your computer and use it in GitHub Desktop.
import Control.Monad
import System.Random
import Data.List
size :: Int
size = 3
steps :: Int
steps = 10000
main :: IO ()
main = do
results <- replicateM steps (simulate size)
print $ avg results
simulate :: Int -> IO Int
simulate k = do
gen <- newStdGen
let ns = randomRs (1,k) gen
return $ length $ takeWhile ((<k) . length . nub) $ inits ns
avg :: [Int] -> Float
avg xs = fromIntegral (sum xs) / genericLength xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment