June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,7 +1,9 @@
function montepi(n)
s = 0
for i = 1:n
s += rand()^2 + rand()^2 < 1
end
return 4*s/n
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%%", abs(p - π) / π))
end