Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Monte-Carlo-methods/Elixir/monte-carlo-methods.elixir
Normal file
14
Task/Monte-Carlo-methods/Elixir/monte-carlo-methods.elixir
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
defmodule MonteCarlo do
|
||||
def pi(n) do
|
||||
count = Enum.count(1..n, fn _ ->
|
||||
x = :rand.uniform
|
||||
y = :rand.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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue