let S = 0.0 k = 0 tol = 1e-4 #you can change this into 1e-8 but it takes too long by design while true S += (-1.0)^k / (2k + 1) if abs(4S - pi) < tol break end k += 1 end println("Smallest n = ", k) println("Approximation of π = ", 4S) end """ Playing around with the tolerance (basically just lowering it and then gradually raising it, say start from tol=10^(-3), i.e. 1e-3, and dividing it by 10 each time) we find out that the number of iterations needed also multiply by 10, so for a tolerance of 1e-8 we need ~1 trillion iterations which is why this takes so long. Part of programming is also questioning what one is already """