julia> big(pi)
3.141592653589793238462643383279502884197169399375105820974944592307816406286198e+00 with 256 bits of precision
function droplet_pi(n)
Pi = p = ""
no_nines = 0
d = n + 2
N = ifloor(10*d/3.0 + 1)
a = fill(2, N+1)
for l in 1:d
a = 10 * a
for i in (N+1):-1:2
j = 2*i - 1
q, r = divrem(a[i], j)
a[i] = r
a[i-1] += q * (i-1)
end
q, r = divrem(a[1], 10)
a[1] = r
if q < 9
Pi *= string(p) * ("9"^no_nines)
p = q
no_nines = 0
elseif q == 9
no_nines += 1
elseif q == 10
p += 1
Pi *= string(p) * ("0"^no_nines)
p = 0
no_nines = 0
else
error("droplet_pi: algorithm error!")
end
end
Pi[1:1] * "." * Pi[2:end]
end
buffon needle could be one
@Steven
Do you think it was no fun to implement the droplet/spigot algorithm? Then you may be completely wrong.
function sumalt(s_alt, n)
b = 2^(2*n-1)
c = b
s = 0.0
for k in (n-1):-1:0
t = s_alt[k+1]
s = s + c*t
b = b * (2*k+1) * (k+1) / (2 * (n-k) * (n+k))
c = c + b
end
s = s / c
return(s)
end
With about a week left, I'd love to find out how many digits of π we can get only from Julia.Perhaps we can coordinate a worldwide distributed computation this week.