2 Approximations of π In Only Four Lines of Code!
I just recently noticed I haven't programmed in Python in a while and what better thing to do than approximate π!
After all, it is Pi
Python! (Sorry for the poor Markdown rendering. This is supposed to be "Python" with "Py" crossed out and "Pi" inserted.)
(Also, some inspiration from the many π approximation Python repls by @LizFoster )
And here are two approximations of π using infinite series in just four lines of code!
By the way, for anyone who is wondering, this is the Nilakantha Series and an infinite series for the radian arctangent of 1 multiplied by 4 (in radians, the arctangent of 1 is π/4, although you might just know it as 45 degrees).
And yes, the arctangent method is VERY slow.
New Node.JS version in just one line: