Monte Carlo methods: Difference between revisions
Content added Content deleted
Line 1,298: | Line 1,298: | ||
<lang haskell>import Control.Monad (foldM, (>=>)) |
<lang haskell>import Control.Monad (foldM, (>=>)) |
||
import System.Random (randomRIO) |
import System.Random (randomRIO) |
||
import Data.Functor ((<&>)) |
|||
------- APPROXIMATION TO PI BY A MONTE CARLO METHOD ------ |
------- APPROXIMATION TO PI BY A MONTE CARLO METHOD ------ |
||
Line 1,307: | Line 1,308: | ||
where |
where |
||
rnd = randomRIO (0, 1) :: IO Double |
rnd = randomRIO (0, 1) :: IO Double |
||
go a _ = rnd >>= ( |
go a _ = rnd >>= ((<&>) rnd . f a) |
||
f x y |
f a x y |
||
| 1 > x ** 2 + y ** 2 = succ |
| 1 > x ** 2 + y ** 2 = succ a |
||
| otherwise = |
| otherwise = a |
||
--------------------------- TEST ------------------------- |
--------------------------- TEST ------------------------- |