Created
March 25, 2015 22:32
-
-
Save sphynx/ba48d74c854dd7bb2a7a to your computer and use it in GitHub Desktop.
This file contains 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 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