The Digits of Pi

February 20, 2009

The ratio of the circumference of a circle to its diameter is given by the constant known by the Greek letter pi, and is an irrational number (its representation is non-terminating and non-repeating) with a value slightly larger than 3.14159. What is the one-thousandth digit of pi? (Counting begins at zero, so the zeroth digit of pi is 3 and the fourth digit of pi is 5.)


Pages: 1 2

2 Responses to “The Digits of Pi”

  1. Matt Weaver said

    My solution, written in C:

    http://codepad.org/WOEQnbTt

    This version calculates the requested digit directly, based on the method described in “Computation of the nth decimal digit of pi with low memory”: http://numbers.computation.free.fr/Constants/Algorithms/nthdecimaldigit.pdf (and I must admit I also peeked a little at the implementation at http://numbers.computation.free.fr/Constants/Algorithms/nthdigit.html)

    It lacks the conciseness and elegance of the spigot solution, but makes up for it in efficiency. The spigot version works well until it runs out of main memory and starts paging, at which point performance really hits a wall. On my computer that point is somewhere between the 20,000th digit (took 1:48) and the 50,000th (I killed it after 3.5 hours). For comparison, this solution returns the 50,000th digit in ~12 seconds.

  2. programmingpraxis said

    Alexander J. Yee & Shigeru Kondo recently computed five trillion digits of pi.

Leave a Reply