Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main where
- --compile as ghc -threaded --make $file.hs -o boygirl
- --run as ./boygirl [# of sims] [# of families] +RTS -N[# of CPUS]
- import System.Environment(getArgs)
- import System.Random(newStdGen,randoms)
- main :: IO ()
- main = do
- g <- newStdGen
- (c:n:_) <- getArgs
- printResults (read c) (read n) (randoms g)
- runSim :: Int -> Int -> [Bool] -> Double -> Double -> (Double, Double)
- runSim c n bs gx bx = let (g,b,restbs) = howmany n bs 0 0 in
- if c == 0 then (gx+(avgUp g b),bx+(avgUp b g)) else runSim (c-1) n restbs (gx+(avgUp g b)) (bx+(avgUp b g))
- avgUp :: Int -> Int -> Double
- avgUp x y = x' / (x'+y') where
- x' = fromIntegral x
- y' = fromIntegral y
- printResults c n bs = let (gx,bx) = runSim c n bs 0 0
- c' = fromIntegral c in
- do
- putStrLn $ "Sims: " ++ (show c)
- putStrLn $ "Avg Girls Fraction: " ++ (show (gx/ c'))
- putStrLn $ "Avg Boys Fraction: " ++ (show (bx / c'))
- howmany :: Int -> [Bool] -> Int -> Int -> (Int,Int,[Bool])
- howmany n rs grrls bois | n == 0 = (grrls,bois,rs)
- | (head rs) = howmany n (tail rs) (grrls+1) bois
- | not (head rs) = howmany (n-1) (tail rs) grrls (bois+1)
Advertisement
Add Comment
Please, Sign In to add comment