October 17th, 2009


Computing the circumference of a circle when you don't know pi.

Dear Proggit: Imagine that you must devise a method to calculate the circumference of a circle of any radius. The catch? You are unaware of the existence of Pi.

An interesting little problem, definitely worthy of an hour with a compiler...

Though you can certainly do this very accurately with calculus (see "Some examples" here), my first thought was to approximate the circle with a bunch of secant chords, and sum up their lengths. Basically just applying the Trapezoidal Rule for numeric integration to a circle.

You can see the results here, and view the source code for the program at http://www.gully.org/~mackys/picalc.c.txt.

As noted, it doesn't converge very fast and it's not particularly accurate. I'm certain there are ten thousand ways to improve it. But it was fun for a little one hour problem.