Created
September 24, 2015 02:02
-
-
Save rinx/076c9816f96971fcea86 to your computer and use it in GitHub Desktop.
monte carlo with haskell
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
{-# LANGUAGE ExtendedDefaultRules, NoMonomorphismRestriction #-} | |
import Conduit | |
main :: IO () | |
main = do | |
let cnt = 100000000 | |
successes <- sourceRandomN cnt $$ lengthIfC (\(x, y) -> x*x + y*y < 1) | |
print $ successes / cnt * 4 | |
-- https://www.fpcomplete.com/blog/2014/03/monte-carlo-haskell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment