On Thu, 13 Jul 2006, Jason Holt wrote:
Let's see if I can write it as a formula instead of an algorithm:
n n 4 ___ ___ --- \ \ pi ~ n*n * / / 1 if sqrt(x*x+y*y) < n --- --- x=0 y=0
We coded up the algorithm and ran it for varying values of n. Here's the result for n=3,000,000, which took 23 hours on our Athlon64 3000+: ... area = 7068586468447 pi=3.141593985976 (pi/realpi=1.000000424112) Command exited with non-zero status 45 79435.25user 490.80system 23:26:48elapsed Not the most quickly converging series, but it did get to within 0.00004% of the true value! Next his younger brother is going to code up a guess-and-check square root program, so that we can run the whole program using only elementary operations (+-*/). Then we'll try some optimizations on the pi algorithm, like the discrete integration I mentioned, and finish up with a sin/cos/tan calculator using only the pythagorean theorem. All of this makes a great introduction to programming, too. -J