Calculating pi using a needle

Last night I read a very interesting article in NyTeknik. It described the art of calculating pi using only a needle. What you do is that you drop a needle on board flooring. The needle needs to be the same length as the distance between two boards. Every time the needle lands on the narrow opening between two boards you note that. Call the number of times that happens n. When you have repeated the drop N times you get pi by divide 2*N with n. To get a good approximation of pi you need to make sure N is a large number. And to do that you’ll need patience :)

At least I don’t have that kind of patience so I wrote a program to do it for me. And, indeed, it works. But it isn’t a good algorithm. It takes a huge number of iterations to get even the first five decimals correct. So I think I’ll stick to using M_PI in my programs ;)

Proof that this works: in Swedish and in English.

Posted Thursday, December 9th, 2004 under misc.

Comments are closed.