Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,15 @@
defmodule MonteCarlo do
def pi(n) do
:random.seed(:os.timestamp)
count = Enum.count(1..n, fn _ ->
x = :random.uniform
y = :random.uniform
:math.sqrt(x*x + y*y) <= 1
end)
4 * count / n
end
end
Enum.each([1000, 10000, 100000, 1000000, 10000000], fn n ->
:io.format "~8w samples: PI = ~f~n", [n, MonteCarlo.pi(n)]
end)