Skip to content

Instantly share code, notes, and snippets.

@rinx
Created September 24, 2015 02:02
Show Gist options
  • Save rinx/076c9816f96971fcea86 to your computer and use it in GitHub Desktop.
Save rinx/076c9816f96971fcea86 to your computer and use it in GitHub Desktop.
monte carlo with haskell
{-# 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