[Math] Pseudo code for calculating $\pi$ using an iterating algorithm

geometrypi

So my question title says it all. What is the best way to calculate $\pi$ as an iterating algorithm that can be programmed into any application (thus the pseudo code)?

$\pi$ Was first calculated using polygons and how an internal perimeter (using a polygon) of a circle compared to the external perimeter (using a polygon) am I correct in saying this? So there must be a way to write the calculation as an iterating algorithm (in pseudo code).

In one of the answers, I found the following formula:

Formula

However, I do not understand what it means as I am a novice in mathematics (only middle school!). What I can make out is $\pi$ = $12 * \sum ((-1)^k*(6k)!(13591409 + 545140134k) )/((3k)!*(k!)^3*640420^{3k+3/2})$ The sum function is repeated to however many iterations needed. I don't understand the variable $k$ or where the formula got the numbers e.g. (6k etc).

Best Answer

See http://en.wikipedia.org/wiki/Chudnovsky_algorithm for the Chudnovsky algorithm for very quickly computing pi accurately, and not too complicated to implement. The algorithm/pseudocode is that you only use the first however many terms in the series (whatever your system can handle in a reasonable computation time), and this will give you a very good approximation.

Related Question