Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Monte-Carlo-methods/Julia/monte-carlo-methods.julia
Normal file
11
Task/Monte-Carlo-methods/Julia/monte-carlo-methods.julia
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using Printf
|
||||
|
||||
function monteπ(n)
|
||||
s = count(rand() ^ 2 + rand() ^ 2 < 1 for _ in 1:n)
|
||||
return 4s / n
|
||||
end
|
||||
|
||||
for n in 10 .^ (3:8)
|
||||
p = monteπ(n)
|
||||
println("$(lpad(n, 9)): π ≈ $(lpad(p, 10)), pct.err = ", @sprintf("%2.5f%%", 100 * abs(p - π) / π))
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue